View Javadoc

1   /*
2    * Copyright (C) The Apache Software Foundation. All rights reserved.
3    *
4    * This software is published under the terms of the Apache Software License
5    * version 1.1, a copy of which has been included with this distribution in
6    * the LICENSE file.
7    * 
8    * $Id: BufferedServletInputStream.java 155459 2005-02-26 13:24:44Z dirkv $
9    */
10  package org.apache.commons.messagelet.impl;
11  
12  import java.io.ByteArrayInputStream;
13  import java.io.IOException;
14  import java.io.InputStream;
15  
16  import javax.servlet.ServletInputStream;
17  
18  /** 
19   * <p><code>BufferedServletInputStream</code> implements
20   * a ServletInputStream using an underlying InputStream.</p>
21   *
22    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
23    * @version $Revision: 155459 $
24   */
25  public class BufferedServletInputStream extends ServletInputStream {
26      
27      protected static final byte[] NO_DATA = new byte[0];
28      
29      /** The underlying <code>InputStream</code> */
30      private InputStream in;
31      
32      
33      public BufferedServletInputStream() {
34          this.in = new ByteArrayInputStream( NO_DATA );
35      }
36      
37      public BufferedServletInputStream(InputStream in) {
38          this.in = in;
39      }
40      
41      public BufferedServletInputStream(String text) {
42          in = new ByteArrayInputStream( text.getBytes() );
43      }
44      
45      public BufferedServletInputStream(byte[] data) {
46          in = new ByteArrayInputStream(data);
47      }
48      
49      // Delegating methods from InputStream
50      //-------------------------------------------------------------------------    
51      
52      public int available() throws IOException {
53          return in.available();
54      }    
55      
56      public void close() throws IOException {
57          in.close();
58      }
59      
60      public void mark(int readlimit) {
61          in.mark(readlimit);
62      }
63      
64      public boolean markSupported() {
65          return in.markSupported();
66      }
67      
68      public int read(byte[] b) throws IOException {
69          return in.read(b);
70      }
71      
72      public int read(byte[] b, int off, int len) throws IOException {
73          return in.read(b, off, len);
74      }
75      
76      public int read() throws IOException {
77          return in.read();
78      }
79          
80      public void reset() throws IOException {
81          in.reset();
82      }    
83      
84      public long skip(long n) throws IOException {
85          return in.skip(n);
86      }    
87  }