Skip to content

Commit 486fce3

Browse files
committed
DataHandle: move metadata query methods to the top
We will soon be adding a few more, such as exists() and lastModified(). It makes sense for these basic interrogation methods to be first.
1 parent b484990 commit 486fce3

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public class BytesHandle extends AbstractDataHandle<BytesLocation> {
5353

5454
// -- DataHandle methods --
5555

56+
@Override
57+
public boolean isReadable() {
58+
return true;
59+
}
60+
61+
@Override
62+
public boolean isWritable() {
63+
return !bytes().isReadOnly();
64+
}
65+
5666
@Override
5767
public long offset() {
5868
return offset;
@@ -86,16 +96,6 @@ public void seek(final long pos) throws IOException {
8696
offset = pos;
8797
}
8898

89-
@Override
90-
public boolean isReadable() {
91-
return true;
92-
}
93-
94-
@Override
95-
public boolean isWritable() {
96-
return !bytes().isReadOnly();
97-
}
98-
9999
// -- DataInput methods --
100100

101101
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public enum ByteOrder {
6565
/** Default bound on bytes to search when searching through the stream. */
6666
int MAX_SEARCH_SIZE = 512 * 1024 * 1024; // 512 MB
6767

68+
/** Gets whether reading from this handle is supported. */
69+
boolean isReadable();
70+
71+
/** Gets whether writing to this handle is supported. */
72+
boolean isWritable();
73+
6874
/** Returns the current offset in the stream. */
6975
long offset() throws IOException;
7076

@@ -116,12 +122,6 @@ default long available(final long count) throws IOException {
116122
return remain < count ? remain : count;
117123
}
118124

119-
/** Gets whether reading from this handle is supported. */
120-
boolean isReadable();
121-
122-
/** Gets whether writing to this handle is supported. */
123-
boolean isWritable();
124-
125125
/**
126126
* Ensures that the handle has sufficient bytes available to read.
127127
*

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public class DummyHandle extends AbstractDataHandle<DummyLocation> {
5353

5454
// -- DataHandle methods --
5555

56+
@Override
57+
public boolean isReadable() {
58+
return true;
59+
}
60+
61+
@Override
62+
public boolean isWritable() {
63+
return true;
64+
}
65+
5666
@Override
5767
public long offset() throws IOException {
5868
return offset;
@@ -74,16 +84,6 @@ public void setLength(final long length) throws IOException {
7484
this.length = length;
7585
}
7686

77-
@Override
78-
public boolean isReadable() {
79-
return true;
80-
}
81-
82-
@Override
83-
public boolean isWritable() {
84-
return true;
85-
}
86-
8787
// -- DataInput methods --
8888

8989
@Override

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,28 @@ public void setMode(final String mode) {
7575
// -- DataHandle methods --
7676

7777
@Override
78-
public long offset() throws IOException {
79-
return raf().getFilePointer();
78+
public boolean isReadable() {
79+
return getMode().contains("r");
8080
}
8181

8282
@Override
83-
public long length() throws IOException {
84-
return raf().length();
83+
public boolean isWritable() {
84+
return getMode().contains("w");
8585
}
8686

8787
@Override
88-
public void setLength(final long length) throws IOException {
89-
raf().setLength(length);
88+
public long offset() throws IOException {
89+
return raf().getFilePointer();
9090
}
9191

9292
@Override
93-
public boolean isReadable() {
94-
return getMode().contains("r");
93+
public long length() throws IOException {
94+
return raf().length();
9595
}
9696

9797
@Override
98-
public boolean isWritable() {
99-
return getMode().contains("w");
98+
public void setLength(final long length) throws IOException {
99+
raf().setLength(length);
100100
}
101101

102102
@Override

0 commit comments

Comments
 (0)