KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > http > httpserver > ServeInputStream


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb.http.httpserver;
22
23 import java.io.*;
24
25 public class ServeInputStream extends InputStream
26     {
27
28     private InputStream in;
29
30     public ServeInputStream( InputStream in )
31     {
32     this.in = in;
33     }
34
35     public int readLine( byte[] b, int off, int len ) throws IOException
36     {
37     int off2 = off;
38     while ( off2 - off < len )
39         {
40         int r = read();
41         if ( r == -1 )
42         {
43         if (off2 == off )
44             return -1;
45         break;
46         }
47         if ( r == 13 )
48         continue;
49         if ( r == 10 )
50         break;
51         b[off2] = (byte) r;
52         ++off2;
53         }
54     return off2 - off;
55     }
56
57     public int read() throws IOException
58     {
59     int b=in.read();
60     return b;
61     }
62
63     public int read( byte[] b, int off, int len ) throws IOException
64     {
65     return in.read( b, off, len );
66     }
67
68     public int available() throws IOException
69     {
70     return in.available();
71     }
72
73     public void close() throws IOException
74     {
75     in.close();
76     }
77
78     }
79
80
81
82
83
84
85
86
87
Popular Tags