01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12:
13: package org.tmatesoft.svn.core.internal.io.dav.http;
14:
15: import java.io.IOException;
16: import java.io.InputStream;
17:
18: /**
19: * @version 1.1.1
20: * @author TMate Software Ltd.
21: */
22: class FixedSizeInputStream extends InputStream {
23:
24: private long myLength;
25: private InputStream mySource;
26:
27: public FixedSizeInputStream(InputStream source, long length) {
28: mySource = source;
29: myLength = length;
30: }
31:
32: public int read() throws IOException {
33: if (myLength > 0) {
34: myLength--;
35: return mySource.read();
36: }
37: return -1;
38: }
39:
40: public void close() {
41: // just read remaining data.
42: if (myLength > 0) {
43: try {
44: consumeRemaining(this );
45: } catch (IOException e) {
46: }
47: }
48: }
49:
50: static void consumeRemaining(InputStream is) throws IOException {
51: byte[] buffer = new byte[1024];
52: while (is.read(buffer) >= 0)
53: ;
54: }
55:
56: }
|