1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/*
* Copyright 2007 - 2018 ETH Zuerich, CISD and SIS.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.hdf5.io;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import ch.systemsx.cisd.base.io.AdapterIInputStreamToInputStream;
import ch.systemsx.cisd.base.io.AdapterIOutputStreamToOutputStream;
import ch.systemsx.cisd.base.io.IInputStream;
import ch.systemsx.cisd.base.io.IOutputStream;
import ch.systemsx.cisd.hdf5.HDF5GenericStorageFeatures;
import ch.systemsx.cisd.hdf5.IHDF5Reader;
import ch.systemsx.cisd.hdf5.IHDF5Writer;
/**
* A factory of I/O adapter for HDF5 data sets.
*
* @author Bernd Rinn
*/
public class HDF5IOAdapterFactory
{
private static final String OPAQUE_TAG_FILE = "FILE";
private final static int BUFFER_SIZE = 1024 * 1024;
//
// File methods
//
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link IOutputStream}.
* <p>
* If the dataset does not yet exist, it will create a chunked opaque dataset with a chunk size
* of 1MB and an opaque tag <code>FILE</code>.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link IOutputStream}.
*/
public static IOutputStream asIOutputStream(File hdf5File, String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE, false);
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link IOutputStream}.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link IOutputStream}.
*/
public static IOutputStream asIOutputStream(File hdf5File, String dataSetPath,
HDF5GenericStorageFeatures creationStorageFeature, int chunkSize, String opaqueTagOrNull)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath, creationStorageFeature,
chunkSize, opaqueTagOrNull, false);
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link HDF5DataSetRandomAccessFile} in
* read/write mode.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFileReadWrite(File hdf5File,
String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE, false);
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link OutputStream}.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link OutputStream}.
*/
public static OutputStream asOutputStream(File hdf5File, String dataSetPath,
HDF5GenericStorageFeatures creationStorageFeature, int chunkSize, String opaqueTagOrNull)
{
return new AdapterIOutputStreamToOutputStream(asIOutputStream(hdf5File, dataSetPath,
creationStorageFeature, chunkSize, opaqueTagOrNull));
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link IOutputStream}.
* <p>
* If the dataset does not yet exist, it will create a chunked opaque dataset with a chunk size
* of 1MB and an opaque tag <code>FILE</code>.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link OutputStream}.
*/
public static OutputStream asOutputStream(File hdf5File, String dataSetPath)
{
return new AdapterIOutputStreamToOutputStream(asIOutputStream(hdf5File, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE));
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link HDF5DataSetRandomAccessFile} in
* read/write mode.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFile(File hdf5File, String dataSetPath,
HDF5GenericStorageFeatures creationStorageFeature, int chunkSize, String opaqueTagOrNull)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath, creationStorageFeature,
chunkSize, opaqueTagOrNull, false);
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link IInputStream}.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link IInputStream}.
*/
public static IInputStream asIInputStream(File hdf5File, String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath, null, 0, null, true);
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link InputStream}.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link InputStream}.
*/
public static InputStream asInputStream(File hdf5File, String dataSetPath)
{
return new AdapterIInputStreamToInputStream(asIInputStream(hdf5File, dataSetPath));
}
/**
* Creates an adapter of the <var>hdf5File</var> as an {@link HDF5DataSetRandomAccessFile} in
* read-only mode.
*
* @param hdf5File The HDF5 file to create the adapter for.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFileReadOnly(File hdf5File,
String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(hdf5File, dataSetPath, null, 0, null, true);
}
//
// Writer methods
//
/**
* Creates an adapter of the <var>writer</var> as an {@link IOutputStream}.
* <p>
* If the dataset does not yet exist, it will create a chunked opaque dataset with a chunk size
* of 1MB and an opaque tag <code>FILE</code>.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link IOutputStream}.
*/
public static IOutputStream asIOutputStream(IHDF5Writer writer, String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(writer, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE, false);
}
/**
* Creates an adapter of the <var>writer</var> as an {@link IOutputStream}.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link IOutputStream}.
*/
public static IOutputStream asIOutputStream(IHDF5Writer writer, String dataSetPath,
HDF5GenericStorageFeatures creationStorageFeature, int chunkSize, String opaqueTagOrNull)
{
return new HDF5DataSetRandomAccessFile(writer, dataSetPath, creationStorageFeature,
chunkSize, opaqueTagOrNull, false);
}
/**
* Creates an adapter of the <var>writer</var> as an {@link IOutputStream}.
* <p>
* If the dataset does not yet exist, it will create a chunked opaque dataset with a chunk size
* of 1MB and an opaque tag <code>FILE</code>.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link OutputStream}.
*/
public static OutputStream asOutputStream(IHDF5Writer writer, String dataSetPath)
{
return new AdapterIOutputStreamToOutputStream(asIOutputStream(writer, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE));
}
/**
* Creates an adapter of the <var>writer</var> as an {@link OutputStream}.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link OutputStream}.
*/
public static OutputStream asOutputStream(IHDF5Writer writer, String dataSetPath,
HDF5GenericStorageFeatures creationStorageFeature, int chunkSize, String opaqueTagOrNull)
{
return new AdapterIOutputStreamToOutputStream(asIOutputStream(writer, dataSetPath,
creationStorageFeature, chunkSize, opaqueTagOrNull));
}
/**
* Creates an adapter of the <var>writer</var> as an {@link HDF5DataSetRandomAccessFile}.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @param creationStorageFeature If the dataset does not yet exist, use this value as the
* storage features when creating it.
* @param chunkSize If the dataset does not yet exist, use this value as the chunk size.
* @param opaqueTagOrNull If the dataset does not yet exist and this value is not
* <code>null</code>, then an opaque dataset will be created using this value will be
* used as opaque tag.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFile(IHDF5Writer writer,
String dataSetPath, HDF5GenericStorageFeatures creationStorageFeature, int chunkSize,
String opaqueTagOrNull)
{
return new HDF5DataSetRandomAccessFile(writer, dataSetPath, creationStorageFeature,
chunkSize, opaqueTagOrNull, false);
}
/**
* Creates an adapter of the <var>writer</var> as an {@link HDF5DataSetRandomAccessFile}.
* <p>
* <b>Note that returned object is buffered. Do not access <var>dataSetPath</var> by directly
* accessing <var>writer</var> while this object is used or else the behavior is undefined!</b>
*
* @param writer The HDF5 writer to create the adapter for. The writer will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFile(IHDF5Writer writer,
String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(writer, dataSetPath,
HDF5GenericStorageFeatures.GENERIC_CHUNKED, BUFFER_SIZE, OPAQUE_TAG_FILE, false);
}
//
// Reader methods
//
/**
* Creates an adapter of the <var>reader</var> as an {@link IInputStream}.
*
* @param reader The HDF5 reader to create the adapter for. The reader will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link IInputStream}.
*/
public static IInputStream asIInputStream(IHDF5Reader reader, String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(reader, dataSetPath, null, 0, null, false);
}
/**
* Creates an adapter of the <var>reader</var> as an {@link InputStream}.
*
* @param reader The HDF5 reader to create the adapter for. The reader will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link InputStream}.
*/
public static InputStream asInputStream(IHDF5Reader reader, String dataSetPath)
{
return new AdapterIInputStreamToInputStream(asIInputStream(reader, dataSetPath));
}
/**
* Creates an adapter of the <var>reader</var> as an {@link HDF5DataSetRandomAccessFile}.
*
* @param reader The HDF5 reader to create the adapter for. The reader will <i>not be closed
* when the returned object is closed.
* @param dataSetPath The path of the HDF5 dataset in the HDF5 container to use as a file.
* @return The {@link HDF5DataSetRandomAccessFile}.
*/
public static HDF5DataSetRandomAccessFile asRandomAccessFile(IHDF5Reader reader,
String dataSetPath)
{
return new HDF5DataSetRandomAccessFile(reader, dataSetPath, null, 0, null, false);
}
}
|