Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/main/java/org/scijava/io/handle/DataHandleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.scijava.io.handle;

import java.io.IOException;
import java.util.Objects;

import org.scijava.io.IOService;
import org.scijava.io.location.Location;
Expand Down Expand Up @@ -72,12 +71,13 @@ default Class<Location> getType() {
*
* @param location the location to test
* @return The result of {@link DataHandle#exists()} on a newly created handle
* on this location
* @throws IOException
* on this location. Also returns {@code false} if the handle can not
* be created.
* @throws IOException if the creation of the handle fails exceptionally
*/
default boolean exists(final Location location) throws IOException {
try (DataHandle<Location> handle = create(location)) {
return handle.exists();
return handle == null ? false : handle.exists();
}
}

Expand All @@ -86,18 +86,22 @@ default boolean exists(final Location location) throws IOException {
* reading.
*
* @param handle the handle to wrap
* @return The handle wrapped in a read-only buffer, or {@code null} if the
* input handle is {@code null}
* @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle)
*/
default DataHandle<Location> readBuffer(final DataHandle<Location> handle) {
Objects.nonNull(handle);
return new ReadBufferDataHandle(handle);
return handle == null ? null : new ReadBufferDataHandle(handle);
}

/**
* Creates a {@link DataHandle} on the provided {@link Location} wrapped in a
* read-only buffer for accelerated reading.
*
* @param location the handle to wrap
* @param location the Location to create a buffered handle on.
* @return A {@link DataHandle} on the provided location wrapped in a
* read-only buffer, or {@code null} if no handle could be created for
* the location.
* @see ReadBufferDataHandle#ReadBufferDataHandle(DataHandle)
*/
default DataHandle<Location> readBuffer(final Location location) {
Expand All @@ -110,10 +114,11 @@ default DataHandle<Location> readBuffer(final Location location) {
* accelerated writing.
*
* @param handle the handle to wrap
* @return the handle wrapped in a write-only buffer or {@code null} if the
* provided handle is {@code null}
* @see WriteBufferDataHandle#WriteBufferDataHandle(DataHandle)
*/
default DataHandle<Location> writeBuffer(final DataHandle<Location> handle) {
Objects.nonNull(handle);
return new WriteBufferDataHandle(handle);
return handle == null ? null : new WriteBufferDataHandle(handle);
}
}