Skip to content

Commit b65ff9a

Browse files
committed
DataHandleService: Prominently expose ReadBufferDataHandle and WriteBufferDataHandle
1 parent ef1268b commit b65ff9a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
package org.scijava.io.handle;
3434

3535
import java.io.IOException;
36+
import java.util.Objects;
3637

3738
import org.scijava.io.IOService;
3839
import org.scijava.io.location.Location;
@@ -79,4 +80,40 @@ default boolean exists(final Location location) throws IOException {
7980
return handle.exists();
8081
}
8182
}
83+
84+
/**
85+
* Wraps the provided {@link DataHandle} in a read-only buffer for accelerated
86+
* reading.
87+
*
88+
* @param handle the handle to wrap
89+
* @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle)
90+
*/
91+
default DataHandle<Location> readBuffer(final DataHandle<Location> handle) {
92+
Objects.nonNull(handle);
93+
return new ReadBufferDataHandle(handle);
94+
}
95+
96+
/**
97+
* Creates a {@link DataHandle} on the provided {@link Location} wrapped in a
98+
* read-only buffer for accelerated reading.
99+
*
100+
* @param location the handle to wrap
101+
* @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle)
102+
*/
103+
default DataHandle<Location> readBuffer(final Location location) {
104+
final DataHandle<Location> handle = create(location);
105+
return handle == null ? null : new ReadBufferDataHandle(handle);
106+
}
107+
108+
/**
109+
* Wraps the provided {@link DataHandle} in a write-only buffer for
110+
* accelerated writing.
111+
*
112+
* @param handle the handle to wrap
113+
* @see WriteBufferDataHandle#WriteBufferDataHandle(DataHandle)
114+
*/
115+
default DataHandle<Location> writeBuffer(final DataHandle<Location> handle) {
116+
Objects.nonNull(handle);
117+
return new WriteBufferDataHandle(handle);
118+
}
82119
}

0 commit comments

Comments
 (0)