File: DisconnectableInputStream.java

package info (click to toggle)
libjlha-java 0.0.20050504-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,364 kB
  • ctags: 1,338
  • sloc: java: 10,782; xml: 139; makefile: 14
file content (275 lines) | stat: -rw-r--r-- 9,842 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//start of DisconnectableInputStream.java
//TEXT_STYLE:CODE=Shift_JIS(Japanese):RET_CODE=CRLF

/**
 * DisconnectableInputStream.java
 * 
 * Copyright (C) 2001-2002  Michel Ishizuka  All rights reserved.
 * 
 * ȉ̏ɓӂȂ΃\[XƃoCi`̍ĔzzƎgp
 * ύX̗Lɂ炸‚B
 * 
 * PD\[XR[h̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐ێȂĂ͂ȂȂB
 * 
 * QDoCi`̍ĔzzɂĒ쌠\ ̏̃Xg
 *     щL̐gp ̑̔zz
 *     ܂ގɋLqȂ΂ȂȂB
 * 
 * ̃\tgEFA͐Β˔ڂɂĖۏ؂Œ񋟂A̖
 * IBłƂۏ؁AilLƂۏ؂ɂƂǂ܂炸A
 * Ȃ閾IшÎIȕۏ؂ȂB
 * Β˔ڂ ̃\tgEFA̎gpɂ钼ړIAԐړIA
 * IAȁAT^IȁA邢͕KRIȑQ(gpɂf[^
 * AƖ̒f〈܂Ăv̈⎸A֐i
 * T[rX̓l邪AĂꂾɌ肳Ȃ
 * Q)ɑ΂āAȂ鎖Ԃ̌ƂȂƂĂA_̐
 * C△ߎӔC܂ ȂӔC낤ƂAƂꂪs
 * ŝׂ߂łƂĂA܂͂̂悤ȑQ̉”\
 * ĂƂĂ؂̐ӔC𕉂Ȃ̂ƂB
 */

package jp.gr.java_conf.dangan.io;

//import classes and interfaces
import java.io.InputStream;
import jp.gr.java_conf.dangan.io.Disconnectable;

//import exceptions
import java.io.IOException;
import java.lang.NullPointerException;

/**
 * f[^̓Xg[ f[^
 * ̓Xg[Ƃ̐ڑ邽߂̃[eBeBNXB<br>
 * java.io.BufferedInputStream ̃obt@OXg[
 * Ƃ̐ڑꍇ
 * jp.gr.java_conf.dangan.io.LimitedInputStream gp
 * ڑʒu߂obt@O}~KvB<br>
 * 
 * <pre>
 * -- revision history --
 * $Log: DisconnectableInputStream.java,v $
 * Revision 1.0  2002/07/24 00:00:00  dangan
 * add to version control
 * [maintenance]
 *     ^up~
 *     CZX̏C
 *     \[X
 *
 * </pre>
 * 
 * @author  $Author: dangan $
 * @version $Revision: 1.0 $
 */
public class DisconnectableInputStream extends InputStream
                                       implements Disconnectable {

    //------------------------------------------------------------------
    //  instance field
    //------------------------------------------------------------------
    //  source
    //------------------------------------------------------------------
    //  private InputStream in
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[
     */
    private InputStream in;

    //------------------------------------------------------------------
    //  constructer
    //------------------------------------------------------------------
    //  private DisconnectableInputStream()
    //  public DisconnectableInputStream( InputStream in )
    //------------------------------------------------------------------
    /**
     * ftHgRXgN^B
     * gpsB
     */
    private DisconnectableInputStream(){    }

    /**
     * in Ƃ̐ڑ”\ȓ̓Xg[\zB
     * 
     * @param in ̓Xg[
     */
    public DisconnectableInputStream( InputStream in ){
        if( in != null ){
            this.in = in;
        }else{
            throw new NullPointerException( "in" );
        }
    }


    //------------------------------------------------------------------
    //  java.io.InputStream methods
    //------------------------------------------------------------------
    //  read method
    //------------------------------------------------------------------
    //  public int read()
    //  public int read( byte[] buffer )
    //  public int read( byte[] buffer, int index, int length )
    //  public long skip( long length )
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[ 1oCg̃f[^𓾂B<br>
     * 
     * @return ǂݍ܂ꂽ1oCg̃f[^B<br>
     *         EndOfStreamɒBꍇ -1 ԂB<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public int read() throws IOException {
        return this.in.read();                                                  //throws IOException
    }

    /**
     * ڑꂽ̓Xg[ oCgz buffer 
     * 悤Ƀf[^ǂݍށB<br>
     * f[^͕K buffer 𖞂Ƃ͌ȂƂɒӁB<br>
     * 
     * @param buffer ǂݍ܂ꂽf[^i[邽߂̃oCgz
     * 
     * @return buffer ɓǂݍ񂾃f[^ʂoCgŕԂB<br>
     *          EndOfStream ɒBĂꍇ -1 ԂB<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public int read( byte[] buffer ) throws IOException {
        return this.in.read( buffer, 0, buffer.length );                        //throws IOException
    }

    /**
     * ڑꂽ̓Xg[ oCgz buffer 
     * index Ŏw肳ꂽʒu length oCg̃f[^
     * ǂݍށB<br>
     * f[^͕K length oCgǂݍ܂Ƃ͌
     * ȂƂɒӁB<br>
     * 
     * @param buffer ǂݍ܂ꂽf[^i[邽߂̃oCgz
     * @param index  buffer̃f[^ǂݍ݊Jnʒu
     * @param length bufferɓǂݍރf[^
     * 
     * @return buffer ɓǂݍ񂾃f[^ʂoCgŕԂB<br>
     *          EndOfStream ɒBĂꍇ -1 ԂB<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public int read( byte[] buffer, int index, int length ) throws IOException {
        if( 0 < length ){
            return this.in.read( buffer, index, length );                       //throws IOException
        }else{
            return 0;
        }
    }

    /**
     * ڑꂽ̓Xg[̃f[^ length oCg
     * ǂݔ΂B<br>
     * 
     * @param length ǂݔ΂oCgB<br>
     * 
     * @return ۂɓǂݔ΂ꂽoCgB<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public long skip( long length ) throws IOException {
        if( 0 < length ){
            return this.in.skip( length );                                      //throws IOException
        }else{
            return 0;
        }
    }


    //------------------------------------------------------------------
    //  method of java.io.InputStream
    //------------------------------------------------------------------
    //  mark/reset
    //------------------------------------------------------------------
    //  public void mark( int readLimit )
    //  public void reset()
    //  public boolean markSupprted()
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[݈̌ʒuɃ}[Nݒ肵A
     * reset() \bhŃ}[N_ ǂݍ݈ʒu
     * ߂悤ɂB<br>
     * 
     * @param readLimit }[Nʒuɖ߂ẼoCgB
     *                  ̃oCg𒴂ăf[^ǂ
     *                  񂾏ꍇ reset()łȂȂ
     *                  \B<br>
     */
    public void mark( int readLimit ){
        this.in.mark( readLimit );
    }

    /**
     * ڑꂽ̓Xg[̓ǂݍ݈ʒuŌ
     * mark() \bhĂяoꂽƂ̈ʒuɐݒ肷B<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public void reset() throws IOException {
        this.in.reset();                                                        //throws IOException
    }

    /**
     * ڑꂽ̓Xg[ mark()  reset() 
     * T|[g邩𓾂B<br>
     * 
     * @return Xg[ mark()  reset() 
     *         T|[gꍇ trueB<br>
     *         T|[gȂꍇ falseB<br>
     */
    public boolean  markSupprted(){
        return this.in.markSupported();
    }


    //------------------------------------------------------------------
    //  method of java.io.InputStream
    //------------------------------------------------------------------
    //  other
    //------------------------------------------------------------------
    //  public int available()
    //  public void close()
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[ubNȂ
     * ǂݍނƂ̂łoCg𓾂B<br>
     * 
     * @return ubNȂœǂݏooCgB<br>
     * 
     * @exception IOException o̓G[ꍇ
     */
    public int available() throws IOException {
        return this.in.available();                                             //throws IOException
    }

    /**
     * ڑꂽ̓Xg[Ƃ̐ڑB<br>
     * ̃\bh disconnect() ĂԂłB<br>
     */
    public void close(){
        this.disconnect();
    }


    //------------------------------------------------------------------
    //  method of jp.gr.java_conf.dangan.io.Disconnectable 
    //------------------------------------------------------------------
    //  public void disconnect
    //------------------------------------------------------------------
    /**
     * ڑꂽ̓Xg[Ƃ̐ڑB<br>
     */
    public void disconnect(){
        this.in = null;
    }

}
//end of DisconnectableInputStream.java