/[classpath]/inetlib/source/gnu/inet/util/LineInputStream.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/util/LineInputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dog, Sun Oct 19 08:51:37 2003 UTC revision 1.2 by dog, Sun Oct 19 16:16:50 2003 UTC
# Line 38  import java.io.IOException; Line 38  import java.io.IOException;
38   * @author <a href="mailto:dog@gnu.org">Chris Burdess</a>   * @author <a href="mailto:dog@gnu.org">Chris Burdess</a>
39   * @version $Revision$ $Date$   * @version $Revision$ $Date$
40   */   */
41  public class LineInputStream  public class LineInputStream extends FilterInputStream
   extends FilterInputStream  
42  {  {
43    
44          /*    /*
45           * Line buffer.     * Line buffer.
46           */     */
47    private ByteArrayOutputStream buf;    private ByteArrayOutputStream buf;
48    
49          /*    /*
50           * Encoding to use when translating bytes to characters.     * Encoding to use when translating bytes to characters.
51           */     */
52          private String encoding;    private String encoding;
53    
54          /*    /*
55           * End-of-stream flag.     * End-of-stream flag.
56           */     */
57          private boolean eof;    private boolean eof;
58    
59    /**    /**
60     * Constructor using the US-ASCII character encoding.     * Constructor using the US-ASCII character encoding.
# Line 63  public class LineInputStream Line 62  public class LineInputStream
62     */     */
63    public LineInputStream(InputStream in)    public LineInputStream(InputStream in)
64    {    {
65                  this(in, "US-ASCII");      this(in, "US-ASCII");
66    }    }
67      
68    /**    /**
69     * Constructor.     * Constructor.
70     * @param in the underlying input stream     * @param in the underlying input stream
# Line 73  public class LineInputStream Line 72  public class LineInputStream
72     */     */
73    public LineInputStream(InputStream in, String encoding)    public LineInputStream(InputStream in, String encoding)
74    {    {
75                  super(in);      super(in);
76      buf = new ByteArrayOutputStream();      buf = new ByteArrayOutputStream();
77                  this.encoding = encoding;      this.encoding = encoding;
78                  eof = false;      eof = false;
79          }    }
80            
81    /**    /**
82     * Read a line of input.     * Read a line of input.
83     */     */
84    public String readLine()    public String readLine() throws IOException
     throws IOException  
85    {    {
86                  if (eof)      if (eof)
87                          return null;        return null;
88                  do      do
89                  {      {
90                          int c = in.read();        int c = in.read();
91                          switch (c)        switch (c)
92                          {        {
93                                  case -1:        case -1:
94                                          eof = true;          eof = true;
95                                  case 10: // LF          case 10:                // LF
96                                          String ret = buf.toString(encoding);          String ret = buf.toString(encoding);
97                                          buf.reset();          buf.reset();
98                                          return ret;          return ret;
99                                  default:          default:buf.write(c);
100                                          buf.write(c);        }
101                          }      }
102                  } while (true);      while (true);
103          }    }
104    
105  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26