BufferedResourceLoader.java revision 56ed4167b942ec265f9cee70ac4d71d10b3835ce
1/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.clearsilver.jsilver.resourceloader;
18
19import java.io.Reader;
20import java.io.BufferedReader;
21
22/**
23 * Base class for ResourceLoader implementations that require the Reader to be buffered (i.e.
24 * there's IO latency involved).
25 *
26 * @see ResourceLoader
27 */
28public abstract class BufferedResourceLoader extends BaseResourceLoader {
29
30  public static final int DEFAULT_BUFFER_SIZE = 1024;
31  public static final String DEFAULT_CHARACTER_SET = "UTF-8";
32
33  private int bufferSize = DEFAULT_BUFFER_SIZE;
34  private String characterSet = DEFAULT_CHARACTER_SET;
35
36  /**
37   * Subclasses can wrap a Reader in a BufferedReader by calling this method.
38   */
39  protected Reader buffer(Reader reader) {
40    return reader == null ? null : new BufferedReader(reader, bufferSize);
41  }
42
43  public int getBufferSize() {
44    return bufferSize;
45  }
46
47  public void setBufferSize(int bufferSize) {
48    this.bufferSize = bufferSize;
49  }
50
51  public void setCharacterSet(String characterSet) {
52    this.characterSet = characterSet;
53  }
54
55  public String getCharacterSet() {
56    return characterSet;
57  }
58
59}
60