|
33 | 33 | package org.scijava.io.handle; |
34 | 34 |
|
35 | 35 | import java.io.IOException; |
| 36 | +import java.util.Objects; |
36 | 37 |
|
37 | 38 | import org.scijava.io.IOService; |
38 | 39 | import org.scijava.io.location.Location; |
@@ -79,4 +80,40 @@ default boolean exists(final Location location) throws IOException { |
79 | 80 | return handle.exists(); |
80 | 81 | } |
81 | 82 | } |
| 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 | + } |
82 | 119 | } |
0 commit comments