Skip to content

Commit 9a91f38

Browse files
committed
WIP: Update to new API changes
1 parent d322704 commit 9a91f38

19 files changed

+126
-58
lines changed

src/main/java/org/scijava/io/handle/DefaultBufferedStreamHandle.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void seek(final long pos) throws IOException {
105105
}
106106

107107
private long maxBuf() throws IOException {
108-
return getBufferIfOpen().getMaxPos();
108+
return getBufferIfOpen().size();
109109
}
110110

111111
@Override
@@ -231,4 +231,9 @@ private ByteBank getBufferIfOpen() throws IOException {
231231
}
232232
return buffer;
233233
}
234+
235+
@Override
236+
public boolean exists() throws IOException {
237+
return false;
238+
}
234239
}

src/main/java/org/scijava/io/location/AbstractCompressedHandle.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
import java.io.InputStream;
3636
import java.io.OutputStream;
3737

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;
4142
import org.scijava.plugin.Parameter;
4243

4344
/**
@@ -79,6 +80,13 @@ public InputStream in() throws IOException {
7980
return inputStream;
8081
}
8182

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+
8290
protected abstract void initInputStream() throws IOException;
8391

8492
@Override
@@ -101,6 +109,11 @@ public long length() throws IOException {
101109
return raw().length();
102110
}
103111

112+
@Override
113+
public boolean exists() throws IOException {
114+
return raw().exists();
115+
}
116+
104117
@Override
105118
public void setLength(long length) throws IOException {
106119
throw new IOException("This handle " + this.getClass().getSimpleName() +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

src/main/java/org/scijava/io/location/bzip2/BZip2Handle.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import java.io.IOException;
3535

36-
import org.scijava.io.DataHandle;
36+
import org.scijava.io.handle.DataHandle;
3737
import org.scijava.io.location.AbstractCompressedHandle;
3838
import org.scijava.plugin.Plugin;
3939

@@ -60,5 +60,4 @@ protected void initInputStream() throws IOException {
6060
public Class<BZip2Location> getType() {
6161
return BZip2Location.class;
6262
}
63-
6463
}

src/main/java/org/scijava/io/location/bzip2/BZip2Location.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
package org.scijava.io.location.bzip2;
33

4-
import org.scijava.io.DataHandle;
5-
import org.scijava.io.Location;
4+
import org.scijava.io.handle.DataHandle;
65
import org.scijava.io.location.AbstractHigherOrderLocation;
6+
import org.scijava.io.location.Location;
77

88
/**
99
* {@link Location} backed by a {@link DataHandle} that is BZip2 compressed.

src/main/java/org/scijava/io/location/bzip2/CBZip2InputStream.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
import java.io.IOException;
5757
import java.io.InputStream;
5858

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;
6161
import org.scijava.log.LogService;
6262

6363
/**

src/main/java/org/scijava/io/location/gzip/GZipHandle.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import java.io.IOException;
3434
import java.util.zip.GZIPInputStream;
3535

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;
3838
import org.scijava.io.location.AbstractCompressedHandle;
3939
import org.scijava.plugin.Plugin;
4040

src/main/java/org/scijava/io/location/gzip/GZipLocation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
package org.scijava.io.location.gzip;
33

4-
import org.scijava.io.DataHandle;
5-
import org.scijava.io.Location;
4+
import org.scijava.io.handle.DataHandle;
65
import org.scijava.io.location.AbstractHigherOrderLocation;
6+
import org.scijava.io.location.Location;
77

88
/**
99
* {@link Location} backed by a {@link DataHandle} that is <code>gzip</code>

src/main/java/org/scijava/io/location/zip/ZipHandle.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import java.util.zip.ZipEntry;
3636
import java.util.zip.ZipInputStream;
3737

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;
4142
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;
4444
import org.scijava.plugin.Plugin;
4545

4646
/**
@@ -202,4 +202,16 @@ protected void initInputStream() throws IOException {
202202
resetStream();
203203
}
204204
}
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+
}
205217
}

src/main/java/org/scijava/io/location/zip/ZipLocation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
import java.util.zip.ZipEntry;
3535

36-
import org.scijava.io.DataHandle;
37-
import org.scijava.io.Location;
36+
import org.scijava.io.handle.DataHandle;
3837
import org.scijava.io.location.AbstractHigherOrderLocation;
38+
import org.scijava.io.location.Location;
3939
import org.scijava.plugin.Plugin;
4040

4141
/**

src/test/java/org/scijava/io/BZip2HandleTest.java src/test/java/org/scijava/io/handle/BZip2HandleTest.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@
2929
* #L%
3030
*/
3131

32-
package org.scijava.io;
32+
package org.scijava.io.handle;
3333

3434
import java.io.File;
3535
import java.io.FileOutputStream;
3636
import java.io.IOException;
3737

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;
3843
import org.scijava.io.location.bzip2.BZip2Handle;
3944
import org.scijava.io.location.bzip2.BZip2Location;
40-
import org.scijava.io.location.file.FileLocation;
4145

4246
/**
4347
* Tests {@link BZip2Handle}.
@@ -76,16 +80,19 @@ public Location createLocation() throws IOException {
7680
return new BZip2Location(new FileLocation(bzip2File));
7781
}
7882

83+
@Test
7984
@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
8487
}
8588

8689
@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+
}
8996
}
9097

9198
}

src/test/java/org/scijava/io/handle/DataHandleTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void testEndianesSettings() throws IOException {
113113
@Test
114114
public void testReading() throws IOException {
115115
try (final DataHandle<? extends Location> handle = createHandle()) {
116-
checkBasicReadMethods(handle);
116+
checkBasicReadMethods(handle, true);
117117
checkEndiannessReading(handle);
118118
}
119119
}
@@ -168,13 +168,16 @@ public void populateData(final OutputStream out) throws IOException {
168168
* Checks basic byte reading methods.
169169
*
170170
* @param handle the handle to test
171+
* @param checkLength whether to check the total length of the handle
171172
* @throws IOException
172173
*/
173174
public <L extends Location> void checkBasicReadMethods(
174-
final DataHandle<L> handle) throws IOException
175+
final DataHandle<L> handle, boolean checkLength) throws IOException
175176
{
176177
assertEquals(0, handle.offset());
177-
assertEquals(BYTES.length, handle.length());
178+
if (checkLength) {
179+
assertEquals(BYTES.length, handle.length());
180+
}
178181
assertEquals("UTF-8", handle.getEncoding());
179182

180183
// test read()

src/test/java/org/scijava/io/GZipHandleTest.java src/test/java/org/scijava/io/handle/GZipHandleTest.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
* #L%
3030
*/
3131

32-
package org.scijava.io;
32+
package org.scijava.io.handle;
3333

3434
import java.io.File;
3535
import java.io.FileOutputStream;
3636
import java.io.IOException;
3737
import java.util.zip.GZIPOutputStream;
3838

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;
4043
import org.scijava.io.location.gzip.GZipHandle;
4144
import org.scijava.io.location.gzip.GZipLocation;
4245

@@ -68,14 +71,18 @@ public Location createLocation() throws IOException {
6871
return new GZipLocation(new FileLocation(tmpFile));
6972
}
7073

74+
@Test
7175
@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
7678
}
79+
7780
@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+
}
8087
}
8188
}

src/test/java/org/scijava/io/handle/ReadBufferDataHandleTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testSmallBuffer() throws IOException {
6464
new ReadBufferDataHandle(handle, 5))
6565
{
6666
// check with small buffersize
67-
checkBasicReadMethods(bufferedHandle);
67+
checkBasicReadMethods(bufferedHandle, true);
6868
checkEndiannessReading(bufferedHandle);
6969
}
7070
}
@@ -127,7 +127,6 @@ public void testLargeRead() throws Exception {
127127
}
128128

129129
@Test
130-
@Ignore
131130
@Override
132131
public void testWriting() throws IOException {
133132
// nothing to do here

src/test/java/org/scijava/io/handle/WriteBufferDataHandleTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ public DataHandle<? extends Location> createHandle() {
6464
}
6565

6666
@Test
67-
@Ignore
6867
@Override
6968
public void testReading() throws IOException {
7069
// nothing to do
7170
}
7271

7372
@Test
74-
@Ignore
7573
@Override
7674
public void checkSkip() throws IOException {
7775
// nothing to do

src/test/java/org/scijava/io/ZipHandleTest.java src/test/java/org/scijava/io/handle/ZipHandleTest.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@
2929
* #L%
3030
*/
3131

32-
package org.scijava.io;
32+
package org.scijava.io.handle;
3333

3434
import java.io.File;
3535
import java.io.FileOutputStream;
3636
import java.io.IOException;
3737
import java.util.zip.ZipEntry;
3838
import java.util.zip.ZipOutputStream;
3939

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;
4145
import org.scijava.io.location.zip.ZipHandle;
4246
import org.scijava.io.location.zip.ZipLocation;
4347

@@ -69,15 +73,18 @@ public Location createLocation() throws IOException {
6973
return new ZipLocation(new FileLocation(tmpFile));
7074
}
7175

76+
@Test
7277
@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
7780
}
7881

7982
@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+
}
8289
}
8390
}

0 commit comments

Comments
 (0)