Skip to content

Commit

Permalink
WIP: Update to new API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gab1one committed Oct 15, 2018
1 parent d322704 commit 9a91f38
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void seek(final long pos) throws IOException {
}

private long maxBuf() throws IOException {
return getBufferIfOpen().getMaxPos();
return getBufferIfOpen().size();
}

@Override
Expand Down Expand Up @@ -231,4 +231,9 @@ private ByteBank getBufferIfOpen() throws IOException {
}
return buffer;
}

@Override
public boolean exists() throws IOException {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
import java.io.InputStream;
import java.io.OutputStream;

import org.scijava.io.DataHandle;
import org.scijava.io.DataHandleService;
import org.scijava.io.Location;
import org.scijava.io.handle.AbstractStreamHandle;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.handle.DataHandleService;
import org.scijava.io.handle.ResettableStreamHandle;
import org.scijava.plugin.Parameter;

/**
Expand Down Expand Up @@ -79,6 +80,13 @@ public InputStream in() throws IOException {
return inputStream;
}

@Override
public long skip(long n) throws IOException {
long skipped = in().skip(n);
setOffset(offset() + skipped);
return skipped;
}

protected abstract void initInputStream() throws IOException;

@Override
Expand All @@ -101,6 +109,11 @@ public long length() throws IOException {
return raw().length();
}

@Override
public boolean exists() throws IOException {
return raw().exists();
}

@Override
public void setLength(long length) throws IOException {
throw new IOException("This handle " + this.getClass().getSimpleName() +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

package org.scijava.io.location;

public abstract class AbstractHigherOrderLocation implements Location {

private final Location baseLocation;

public AbstractHigherOrderLocation(final Location location) {
this.baseLocation = location;
}

public Location getBaseLocation() {
return baseLocation;
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/scijava/io/location/bzip2/BZip2Handle.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import java.io.IOException;

import org.scijava.io.DataHandle;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.AbstractCompressedHandle;
import org.scijava.plugin.Plugin;

Expand All @@ -60,5 +60,4 @@ protected void initInputStream() throws IOException {
public Class<BZip2Location> getType() {
return BZip2Location.class;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

package org.scijava.io.location.bzip2;

import org.scijava.io.DataHandle;
import org.scijava.io.Location;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.AbstractHigherOrderLocation;
import org.scijava.io.location.Location;

/**
* {@link Location} backed by a {@link DataHandle} that is BZip2 compressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import java.io.IOException;
import java.io.InputStream;

import org.scijava.io.DataHandle;
import org.scijava.io.Location;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.Location;
import org.scijava.log.LogService;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/io/location/gzip/GZipHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.io.IOException;
import java.util.zip.GZIPInputStream;

import org.scijava.io.DataHandle;
import org.scijava.io.DataHandleInputStream;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.handle.DataHandleInputStream;
import org.scijava.io.location.AbstractCompressedHandle;
import org.scijava.plugin.Plugin;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/io/location/gzip/GZipLocation.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

package org.scijava.io.location.gzip;

import org.scijava.io.DataHandle;
import org.scijava.io.Location;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.AbstractHigherOrderLocation;
import org.scijava.io.location.Location;

/**
* {@link Location} backed by a {@link DataHandle} that is <code>gzip</code>
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/scijava/io/location/zip/ZipHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.scijava.io.DataHandle;
import org.scijava.io.DataHandleInputStream;
import org.scijava.io.Location;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.handle.DataHandleInputStream;
import org.scijava.io.handle.ResettableStreamHandle;
import org.scijava.io.handle.StreamHandle;
import org.scijava.io.location.AbstractCompressedHandle;
import org.scijava.io.location.ResettableStreamHandle;
import org.scijava.io.location.StreamHandle;
import org.scijava.io.location.Location;
import org.scijava.plugin.Plugin;

/**
Expand Down Expand Up @@ -202,4 +202,16 @@ protected void initInputStream() throws IOException {
resetStream();
}
}

@Override
public long length() throws IOException {
if (entry == null) {
return -1;
}
return entry.getSize();
}

public long getEntryLength() {
return entryLength;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/io/location/zip/ZipLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

import java.util.zip.ZipEntry;

import org.scijava.io.DataHandle;
import org.scijava.io.Location;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.AbstractHigherOrderLocation;
import org.scijava.io.location.Location;
import org.scijava.plugin.Plugin;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
* #L%
*/

package org.scijava.io;
package org.scijava.io.handle;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Ignore;
import org.junit.Test;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.FileLocation;
import org.scijava.io.location.Location;
import org.scijava.io.location.bzip2.BZip2Handle;
import org.scijava.io.location.bzip2.BZip2Location;
import org.scijava.io.location.file.FileLocation;

/**
* Tests {@link BZip2Handle}.
Expand Down Expand Up @@ -76,16 +80,19 @@ public Location createLocation() throws IOException {
return new BZip2Location(new FileLocation(bzip2File));
}

@Test
@Override
protected <L extends Location> void checkWrites(DataHandle<L> handle)
throws IOException
{
// NB Handle is read only
public void testWriting() throws IOException {
// no Op
}

@Override
protected void setup() {
checkLength = false;
@Test
public void testReading() throws IOException {
try (final DataHandle<? extends Location> handle = createHandle()) {
checkBasicReadMethods(handle, false);
checkEndiannessReading(handle);
}
}

}
9 changes: 6 additions & 3 deletions src/test/java/org/scijava/io/handle/DataHandleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testEndianesSettings() throws IOException {
@Test
public void testReading() throws IOException {
try (final DataHandle<? extends Location> handle = createHandle()) {
checkBasicReadMethods(handle);
checkBasicReadMethods(handle, true);
checkEndiannessReading(handle);
}
}
Expand Down Expand Up @@ -168,13 +168,16 @@ public void populateData(final OutputStream out) throws IOException {
* Checks basic byte reading methods.
*
* @param handle the handle to test
* @param checkLength whether to check the total length of the handle
* @throws IOException
*/
public <L extends Location> void checkBasicReadMethods(
final DataHandle<L> handle) throws IOException
final DataHandle<L> handle, boolean checkLength) throws IOException
{
assertEquals(0, handle.offset());
assertEquals(BYTES.length, handle.length());
if (checkLength) {
assertEquals(BYTES.length, handle.length());
}
assertEquals("UTF-8", handle.getEncoding());

// test read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
* #L%
*/

package org.scijava.io;
package org.scijava.io.handle;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

import org.scijava.io.location.file.FileLocation;
import org.junit.Ignore;
import org.junit.Test;
import org.scijava.io.location.FileLocation;
import org.scijava.io.location.Location;
import org.scijava.io.location.gzip.GZipHandle;
import org.scijava.io.location.gzip.GZipLocation;

Expand Down Expand Up @@ -68,14 +71,18 @@ public Location createLocation() throws IOException {
return new GZipLocation(new FileLocation(tmpFile));
}

@Test
@Override
protected <L extends Location> void checkWrites(DataHandle<L> handle)
throws IOException
{
// NB Handle is read only
public void testWriting() throws IOException {
// no Op
}

@Override
protected void setup() {
checkLength = false;
@Test
public void testReading() throws IOException {
try (final DataHandle<? extends Location> handle = createHandle()) {
checkBasicReadMethods(handle, false);
checkEndiannessReading(handle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testSmallBuffer() throws IOException {
new ReadBufferDataHandle(handle, 5))
{
// check with small buffersize
checkBasicReadMethods(bufferedHandle);
checkBasicReadMethods(bufferedHandle, true);
checkEndiannessReading(bufferedHandle);
}
}
Expand Down Expand Up @@ -127,7 +127,6 @@ public void testLargeRead() throws Exception {
}

@Test
@Ignore
@Override
public void testWriting() throws IOException {
// nothing to do here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public DataHandle<? extends Location> createHandle() {
}

@Test
@Ignore
@Override
public void testReading() throws IOException {
// nothing to do
}

@Test
@Ignore
@Override
public void checkSkip() throws IOException {
// nothing to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
* #L%
*/

package org.scijava.io;
package org.scijava.io.handle;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.scijava.io.location.file.FileLocation;
import org.junit.Ignore;
import org.junit.Test;
import org.scijava.io.handle.DataHandle;
import org.scijava.io.location.FileLocation;
import org.scijava.io.location.Location;
import org.scijava.io.location.zip.ZipHandle;
import org.scijava.io.location.zip.ZipLocation;

Expand Down Expand Up @@ -69,15 +73,18 @@ public Location createLocation() throws IOException {
return new ZipLocation(new FileLocation(tmpFile));
}

@Test
@Override
protected <L extends Location> void checkWrites(DataHandle<L> handle)
throws IOException
{
// NB Handle is read only
public void testWriting() throws IOException {
// no Op
}

@Override
protected void setup() {
checkLength = false;
@Test
public void testReading() throws IOException {
try (final DataHandle<? extends Location> handle = createHandle()) {
checkBasicReadMethods(handle, false);
checkEndiannessReading(handle);
}
}
}
Loading

0 comments on commit 9a91f38

Please sign in to comment.