File tree 19 files changed +126
-58
lines changed
19 files changed +126
-58
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ public void seek(final long pos) throws IOException {
105
105
}
106
106
107
107
private long maxBuf () throws IOException {
108
- return getBufferIfOpen ().getMaxPos ();
108
+ return getBufferIfOpen ().size ();
109
109
}
110
110
111
111
@ Override
@@ -231,4 +231,9 @@ private ByteBank getBufferIfOpen() throws IOException {
231
231
}
232
232
return buffer ;
233
233
}
234
+
235
+ @ Override
236
+ public boolean exists () throws IOException {
237
+ return false ;
238
+ }
234
239
}
Original file line number Diff line number Diff line change 35
35
import java .io .InputStream ;
36
36
import java .io .OutputStream ;
37
37
38
- import org .scijava .io .DataHandle ;
39
- import org .scijava .io .DataHandleService ;
40
- import org .scijava .io .Location ;
38
+ import org .scijava .io .handle .AbstractStreamHandle ;
39
+ import org .scijava .io .handle .DataHandle ;
40
+ import org .scijava .io .handle .DataHandleService ;
41
+ import org .scijava .io .handle .ResettableStreamHandle ;
41
42
import org .scijava .plugin .Parameter ;
42
43
43
44
/**
@@ -79,6 +80,13 @@ public InputStream in() throws IOException {
79
80
return inputStream ;
80
81
}
81
82
83
+ @ Override
84
+ public long skip (long n ) throws IOException {
85
+ long skipped = in ().skip (n );
86
+ setOffset (offset () + skipped );
87
+ return skipped ;
88
+ }
89
+
82
90
protected abstract void initInputStream () throws IOException ;
83
91
84
92
@ Override
@@ -101,6 +109,11 @@ public long length() throws IOException {
101
109
return raw ().length ();
102
110
}
103
111
112
+ @ Override
113
+ public boolean exists () throws IOException {
114
+ return raw ().exists ();
115
+ }
116
+
104
117
@ Override
105
118
public void setLength (long length ) throws IOException {
106
119
throw new IOException ("This handle " + this .getClass ().getSimpleName () +
Original file line number Diff line number Diff line change
1
+
2
+ package org .scijava .io .location ;
3
+
4
+ public abstract class AbstractHigherOrderLocation implements Location {
5
+
6
+ private final Location baseLocation ;
7
+
8
+ public AbstractHigherOrderLocation (final Location location ) {
9
+ this .baseLocation = location ;
10
+ }
11
+
12
+ public Location getBaseLocation () {
13
+ return baseLocation ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change 33
33
34
34
import java .io .IOException ;
35
35
36
- import org .scijava .io .DataHandle ;
36
+ import org .scijava .io .handle . DataHandle ;
37
37
import org .scijava .io .location .AbstractCompressedHandle ;
38
38
import org .scijava .plugin .Plugin ;
39
39
@@ -60,5 +60,4 @@ protected void initInputStream() throws IOException {
60
60
public Class <BZip2Location > getType () {
61
61
return BZip2Location .class ;
62
62
}
63
-
64
63
}
Original file line number Diff line number Diff line change 1
1
2
2
package org .scijava .io .location .bzip2 ;
3
3
4
- import org .scijava .io .DataHandle ;
5
- import org .scijava .io .Location ;
4
+ import org .scijava .io .handle .DataHandle ;
6
5
import org .scijava .io .location .AbstractHigherOrderLocation ;
6
+ import org .scijava .io .location .Location ;
7
7
8
8
/**
9
9
* {@link Location} backed by a {@link DataHandle} that is BZip2 compressed.
Original file line number Diff line number Diff line change 56
56
import java .io .IOException ;
57
57
import java .io .InputStream ;
58
58
59
- import org .scijava .io .DataHandle ;
60
- import org .scijava .io .Location ;
59
+ import org .scijava .io .handle . DataHandle ;
60
+ import org .scijava .io .location . Location ;
61
61
import org .scijava .log .LogService ;
62
62
63
63
/**
Original file line number Diff line number Diff line change 33
33
import java .io .IOException ;
34
34
import java .util .zip .GZIPInputStream ;
35
35
36
- import org .scijava .io .DataHandle ;
37
- import org .scijava .io .DataHandleInputStream ;
36
+ import org .scijava .io .handle . DataHandle ;
37
+ import org .scijava .io .handle . DataHandleInputStream ;
38
38
import org .scijava .io .location .AbstractCompressedHandle ;
39
39
import org .scijava .plugin .Plugin ;
40
40
Original file line number Diff line number Diff line change 1
1
2
2
package org .scijava .io .location .gzip ;
3
3
4
- import org .scijava .io .DataHandle ;
5
- import org .scijava .io .Location ;
4
+ import org .scijava .io .handle .DataHandle ;
6
5
import org .scijava .io .location .AbstractHigherOrderLocation ;
6
+ import org .scijava .io .location .Location ;
7
7
8
8
/**
9
9
* {@link Location} backed by a {@link DataHandle} that is <code>gzip</code>
Original file line number Diff line number Diff line change 35
35
import java .util .zip .ZipEntry ;
36
36
import java .util .zip .ZipInputStream ;
37
37
38
- import org .scijava .io .DataHandle ;
39
- import org .scijava .io .DataHandleInputStream ;
40
- import org .scijava .io .Location ;
38
+ import org .scijava .io .handle .DataHandle ;
39
+ import org .scijava .io .handle .DataHandleInputStream ;
40
+ import org .scijava .io .handle .ResettableStreamHandle ;
41
+ import org .scijava .io .handle .StreamHandle ;
41
42
import org .scijava .io .location .AbstractCompressedHandle ;
42
- import org .scijava .io .location .ResettableStreamHandle ;
43
- import org .scijava .io .location .StreamHandle ;
43
+ import org .scijava .io .location .Location ;
44
44
import org .scijava .plugin .Plugin ;
45
45
46
46
/**
@@ -202,4 +202,16 @@ protected void initInputStream() throws IOException {
202
202
resetStream ();
203
203
}
204
204
}
205
+
206
+ @ Override
207
+ public long length () throws IOException {
208
+ if (entry == null ) {
209
+ return -1 ;
210
+ }
211
+ return entry .getSize ();
212
+ }
213
+
214
+ public long getEntryLength () {
215
+ return entryLength ;
216
+ }
205
217
}
Original file line number Diff line number Diff line change 33
33
34
34
import java .util .zip .ZipEntry ;
35
35
36
- import org .scijava .io .DataHandle ;
37
- import org .scijava .io .Location ;
36
+ import org .scijava .io .handle .DataHandle ;
38
37
import org .scijava .io .location .AbstractHigherOrderLocation ;
38
+ import org .scijava .io .location .Location ;
39
39
import org .scijava .plugin .Plugin ;
40
40
41
41
/**
Original file line number Diff line number Diff line change 29
29
* #L%
30
30
*/
31
31
32
- package org .scijava .io ;
32
+ package org .scijava .io . handle ;
33
33
34
34
import java .io .File ;
35
35
import java .io .FileOutputStream ;
36
36
import java .io .IOException ;
37
37
38
+ import org .junit .Ignore ;
39
+ import org .junit .Test ;
40
+ import org .scijava .io .handle .DataHandle ;
41
+ import org .scijava .io .location .FileLocation ;
42
+ import org .scijava .io .location .Location ;
38
43
import org .scijava .io .location .bzip2 .BZip2Handle ;
39
44
import org .scijava .io .location .bzip2 .BZip2Location ;
40
- import org .scijava .io .location .file .FileLocation ;
41
45
42
46
/**
43
47
* Tests {@link BZip2Handle}.
@@ -76,16 +80,19 @@ public Location createLocation() throws IOException {
76
80
return new BZip2Location (new FileLocation (bzip2File ));
77
81
}
78
82
83
+ @ Test
79
84
@ Override
80
- protected <L extends Location > void checkWrites (DataHandle <L > handle )
81
- throws IOException
82
- {
83
- // NB Handle is read only
85
+ public void testWriting () throws IOException {
86
+ // no Op
84
87
}
85
88
86
89
@ Override
87
- protected void setup () {
88
- checkLength = false ;
90
+ @ Test
91
+ public void testReading () throws IOException {
92
+ try (final DataHandle <? extends Location > handle = createHandle ()) {
93
+ checkBasicReadMethods (handle , false );
94
+ checkEndiannessReading (handle );
95
+ }
89
96
}
90
97
91
98
}
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ public void testEndianesSettings() throws IOException {
113
113
@ Test
114
114
public void testReading () throws IOException {
115
115
try (final DataHandle <? extends Location > handle = createHandle ()) {
116
- checkBasicReadMethods (handle );
116
+ checkBasicReadMethods (handle , true );
117
117
checkEndiannessReading (handle );
118
118
}
119
119
}
@@ -168,13 +168,16 @@ public void populateData(final OutputStream out) throws IOException {
168
168
* Checks basic byte reading methods.
169
169
*
170
170
* @param handle the handle to test
171
+ * @param checkLength whether to check the total length of the handle
171
172
* @throws IOException
172
173
*/
173
174
public <L extends Location > void checkBasicReadMethods (
174
- final DataHandle <L > handle ) throws IOException
175
+ final DataHandle <L > handle , boolean checkLength ) throws IOException
175
176
{
176
177
assertEquals (0 , handle .offset ());
177
- assertEquals (BYTES .length , handle .length ());
178
+ if (checkLength ) {
179
+ assertEquals (BYTES .length , handle .length ());
180
+ }
178
181
assertEquals ("UTF-8" , handle .getEncoding ());
179
182
180
183
// test read()
Original file line number Diff line number Diff line change 29
29
* #L%
30
30
*/
31
31
32
- package org .scijava .io ;
32
+ package org .scijava .io . handle ;
33
33
34
34
import java .io .File ;
35
35
import java .io .FileOutputStream ;
36
36
import java .io .IOException ;
37
37
import java .util .zip .GZIPOutputStream ;
38
38
39
- import org .scijava .io .location .file .FileLocation ;
39
+ import org .junit .Ignore ;
40
+ import org .junit .Test ;
41
+ import org .scijava .io .location .FileLocation ;
42
+ import org .scijava .io .location .Location ;
40
43
import org .scijava .io .location .gzip .GZipHandle ;
41
44
import org .scijava .io .location .gzip .GZipLocation ;
42
45
@@ -68,14 +71,18 @@ public Location createLocation() throws IOException {
68
71
return new GZipLocation (new FileLocation (tmpFile ));
69
72
}
70
73
74
+ @ Test
71
75
@ Override
72
- protected <L extends Location > void checkWrites (DataHandle <L > handle )
73
- throws IOException
74
- {
75
- // NB Handle is read only
76
+ public void testWriting () throws IOException {
77
+ // no Op
76
78
}
79
+
77
80
@ Override
78
- protected void setup () {
79
- checkLength = false ;
81
+ @ Test
82
+ public void testReading () throws IOException {
83
+ try (final DataHandle <? extends Location > handle = createHandle ()) {
84
+ checkBasicReadMethods (handle , false );
85
+ checkEndiannessReading (handle );
86
+ }
80
87
}
81
88
}
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ public void testSmallBuffer() throws IOException {
64
64
new ReadBufferDataHandle (handle , 5 ))
65
65
{
66
66
// check with small buffersize
67
- checkBasicReadMethods (bufferedHandle );
67
+ checkBasicReadMethods (bufferedHandle , true );
68
68
checkEndiannessReading (bufferedHandle );
69
69
}
70
70
}
@@ -127,7 +127,6 @@ public void testLargeRead() throws Exception {
127
127
}
128
128
129
129
@ Test
130
- @ Ignore
131
130
@ Override
132
131
public void testWriting () throws IOException {
133
132
// nothing to do here
Original file line number Diff line number Diff line change @@ -64,14 +64,12 @@ public DataHandle<? extends Location> createHandle() {
64
64
}
65
65
66
66
@ Test
67
- @ Ignore
68
67
@ Override
69
68
public void testReading () throws IOException {
70
69
// nothing to do
71
70
}
72
71
73
72
@ Test
74
- @ Ignore
75
73
@ Override
76
74
public void checkSkip () throws IOException {
77
75
// nothing to do
Original file line number Diff line number Diff line change 29
29
* #L%
30
30
*/
31
31
32
- package org .scijava .io ;
32
+ package org .scijava .io . handle ;
33
33
34
34
import java .io .File ;
35
35
import java .io .FileOutputStream ;
36
36
import java .io .IOException ;
37
37
import java .util .zip .ZipEntry ;
38
38
import java .util .zip .ZipOutputStream ;
39
39
40
- import org .scijava .io .location .file .FileLocation ;
40
+ import org .junit .Ignore ;
41
+ import org .junit .Test ;
42
+ import org .scijava .io .handle .DataHandle ;
43
+ import org .scijava .io .location .FileLocation ;
44
+ import org .scijava .io .location .Location ;
41
45
import org .scijava .io .location .zip .ZipHandle ;
42
46
import org .scijava .io .location .zip .ZipLocation ;
43
47
@@ -69,15 +73,18 @@ public Location createLocation() throws IOException {
69
73
return new ZipLocation (new FileLocation (tmpFile ));
70
74
}
71
75
76
+ @ Test
72
77
@ Override
73
- protected <L extends Location > void checkWrites (DataHandle <L > handle )
74
- throws IOException
75
- {
76
- // NB Handle is read only
78
+ public void testWriting () throws IOException {
79
+ // no Op
77
80
}
78
81
79
82
@ Override
80
- protected void setup () {
81
- checkLength = false ;
83
+ @ Test
84
+ public void testReading () throws IOException {
85
+ try (final DataHandle <? extends Location > handle = createHandle ()) {
86
+ checkBasicReadMethods (handle , false );
87
+ checkEndiannessReading (handle );
88
+ }
82
89
}
83
90
}
You can’t perform that action at this time.
0 commit comments