source: osm/applications/editors/josm/plugins/opendata/includes/org/j7zip/Common/LimitedSequentialInStream.java

Last change on this file was 36483, checked in by stoecker, 6 days ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 1.1 KB
Line 
1package org.j7zip.Common;
2
3public class LimitedSequentialInStream extends java.io.InputStream {
4 java.io.InputStream _stream; // ISequentialInStream
5 long _size;
6 long _pos;
7
8 public LimitedSequentialInStream() {
9 }
10
11 public void SetStream(java.io.InputStream stream) { // ISequentialInStream
12 _stream = stream;
13 }
14
15 public void Init(long streamSize) {
16 _size = streamSize;
17 _pos = 0;
18 }
19
20 public int read() throws java.io.IOException {
21 int ret = _stream.read();
22 return ret;
23 }
24
25 public int read(byte [] data,int off, int size) throws java.io.IOException {
26 long sizeToRead2 = (_size - _pos);
27 if (size < sizeToRead2) sizeToRead2 = size;
28
29 int sizeToRead = (int)sizeToRead2;
30
31 if (sizeToRead > 0) {
32 int realProcessedSize = _stream.read(data, off, sizeToRead);
33 if (realProcessedSize == -1) {
34 return -1;
35 }
36 _pos += realProcessedSize;
37 return realProcessedSize;
38 }
39
40 return -1; // EOF
41 }
42}
43
Note: See TracBrowser for help on using the repository browser.