hdf5-java_Java HDF5LibraryException類代碼示例

本文汇总了ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException在Java中的常见用法,包括打开、读取、关闭、刷新HDF5文件的相关操作。通过示例代码,展示了如何处理HDF5LibraryException异常,适用于处理HDF5文件的Java开发者。
摘要由CSDN通过智能技术生成

本文整理匯總了Java中ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException類的典型用法代碼示例。如果您正苦於以下問題:Java HDF5LibraryException類的具體用法?Java HDF5LibraryException怎麽用?Java HDF5LibraryException使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

HDF5LibraryException類屬於ncsa.hdf.hdf5lib.exceptions包,在下文中一共展示了HDF5LibraryException類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: open

​點讚 3

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Opens a HDF5 file given its access {@link OpenMode mode}.

*/

private static int open(final File file, final OpenMode mode) {

final int fileId;

try {

if (mode == OpenMode.CREATE) {

file.delete();

file.createNewFile();

}

fileId = H5.H5Fopen(file.getAbsolutePath(), mode.getFlags(), HDF5Constants.H5P_DEFAULT);

} catch (final HDF5LibraryException | IOException e) {

throw new HDF5LibException(

String.format("exception when opening '%s' with %s mode: %s",file.getAbsolutePath(), mode, e.getMessage()), e);

}

if (fileId < 0) {

throw new HDF5LibException(

String.format("failure when opening '%s' for read-only access; negative fileId: %d",file.getAbsolutePath(),fileId)

);

}

return fileId;

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:23,

示例2: readExchanges

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

public synchronized Set readExchanges() throws EodDataSinkException {

if (!isOpen) {

throw new EodDataSinkException("HDF5 File data sink closed!");

}

String[] exchanges = null;

try {

rootGroupHandle = H5.H5Gopen(fileHandle, "/",

HDF5Constants.H5P_DEFAULT);

final H5L_iterate_cb iter_cb = new H5L_iter_callbackT();

final opdata od = new opdata();

@SuppressWarnings("unused")

int status = H5.H5Literate(rootGroupHandle,

HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE,

0L, iter_cb, od);

exchanges = ((H5L_iter_callbackT) iter_cb).getSymbols();

} catch (HDF5LibraryException lex) {

StringBuffer messageBuffer = new StringBuffer();

messageBuffer.append("Failed to iterate over exchanges!");

EodDataSinkException e = new EodDataSinkException(

messageBuffer.toString());

e.initCause(lex);

throw e;

}

return new HashSet(Arrays.asList(exchanges));

}

開發者ID:jsr38,項目名稱:ds3,代碼行數:32,

示例3: close

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Flush and close this file reader.

*

*

* Further file read operations will result in a {@link IllegalStateException}.

*

*/

public void close() {

if (isClosed()) {

return;

}

flush();

try {

H5.H5Fclose(fileId);

fileId = FILE_ID_WHEN_CLOSED;

} catch (final HDF5LibraryException e) {

throw new HDF5LibException(

String.format("failure when closing '%s' from read-only access: %s",file.getAbsolutePath(),e.getMessage()),e);

}

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:21,

示例4: flush

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Flush this file reader (through the HDF5 API) to disk rather than waiting for the OS to handle it.

*/

public void flush() {

if (isClosed()) {

return;

}

try {

H5.H5Fflush(fileId, HDF5Constants.H5F_SCOPE_GLOBAL);

} catch (final HDF5LibraryException e) {

throw new HDF5LibException(

String.format("failure when flushing '%s': %s",file.getAbsolutePath(),e.getMessage()),e);

}

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:15,

示例5: openDataset

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Opens a HDF5 dataSet.

*

* @param fullPath dataset full path.

* @return the dataSet id.

* @throws HDF5LibraryException if there was some error thrown by the HDF5 library.

* @throws HDF5LibException if the HDF5 library returned a invalid dataSet id indicating some kind of issue.

*/

private int openDataset(final String fullPath) throws HDF5LibraryException {

final int dataSetId = H5.H5Dopen(fileId, fullPath, HDF5Constants.H5P_DEFAULT);

if (dataSetId <= 0) {

throw new HDF5LibException(

String.format("opening string data-set '%s' in file '%s' failed with code: %d", fullPath, file, dataSetId));

}

return dataSetId;

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:17,

示例6: findOutGroupChildType

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Returns the type of a group child given.

*

* Type constants are listed in {@link HDF5Constants}, eg.:

*

*

{@link HDF5Constants#H5G_GROUP H5G_GROUP} indicate that the child is another group

*

{@link HDF5Constants#H5G_DATASET H5G_DATASET} indicate that the child is a dataset...

*

*

*

* {@link HDF5Constants#H5G_UNKNOWN H5G_UNKNOWN} indicates that the child is not present.

*

* @param groupId the parent group id. It must be open.

* @param name of the target child.

* @param fullPath full path reported in exceptions when there is an issue.

* @return {@link HDF5Constants#H5G_UNKNOWN H5G_UNKNOWN} if there is no such a child node, other wise any other valid type constant.

* @throws HDF5LibraryException if any is thrown by the HDF5 library.

*/

private int findOutGroupChildType(final int groupId, final String name, final String fullPath) throws HDF5LibraryException {

// Use an single position array to return a value is kinda inefficient but that is the way it is:

final long[] numObjsResult = new long[1];

H5G_info_t result = H5.H5Gget_info(groupId);

numObjsResult[0] = result.nlinks;

final int childCount = (int) numObjsResult[0];

if (childCount == 0) { // this is no premature optimization: get_obj_info_all really cannot handle length 0 arrays.

return HDF5Constants.H5G_UNKNOWN;

} else {

final String[] childNames = new String[childCount];

final int[] childTypes = new int[childCount];

final int[] lTypes = new int[childCount];

final long[] childRefs = new long[childCount];

// Example call in HDF docs (https://www.hdfgroup.org/HDF5/examples/api18-java.html .... H5_Ex_G_Iterate.java Line 71):

// H5.H5Gget_obj_info_all(file_id, DATASETNAME, oname, otype, ltype, orefs, HDF5Constants.H5_INDEX_NAME);

if (H5.H5Gget_obj_info_all(groupId, ".", childNames, childTypes, lTypes, childRefs, HDF5Constants.H5_INDEX_NAME) < 0) {

throw new HDF5LibException(String.format("problem trying to find a group (%s) in file %s", fullPath, file));

}

final int childIndex = ArrayUtils.indexOf(childNames, name);

if (childIndex == -1) {

return HDF5Constants.H5G_UNKNOWN;

} else {

return childTypes[childIndex];

}

}

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:48,

示例7: basicTypeCopyIdSupplier

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Creates a HDF5 type based on a simple copy of a HDF5 type class.

* @param classId the class id to copy.

* @return never {@code null}.

*/

private IntSupplier basicTypeCopyIdSupplier(final int classId) {

return () -> {

try {

return checkH5Result(H5.H5Tcopy(classId), () -> "");

} catch (final HDF5LibraryException ex) {

throw new HDF5LibException("", ex);

}

};

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:15,

示例8: loadLibrary

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Checks whether HDF5 is supported in the current system.

*

* This method won't result in an exception if HDF5 is not currently supported, just return {@code false}.

*

*

* This method will load the corresponding HDF5 library for further use if available.

*

*

* @param tempDir the temporary directory to which all files, including the library itself, are to be extracted

* or {@code null} if the default temporary-file directory is to be used.

*

* This method is synchronized to avoid multiple threads loading the library multiple times.

* @return {@code true} this library is supported on the current hardware+software configuration, {@code false} otherwise.

*/

public static synchronized boolean loadLibrary(final File tempDir) {

if (loaded) {

return true;

}

final String resourcePath = System.mapLibraryName(HDF5_LIB_NAME);

final URL inputUrl = HDF5Library.class.getResource(resourcePath);

if (inputUrl == null) {

logger.warn("Unable to find HDF5 library: " + resourcePath);

return false;

}

logger.info(String.format("Trying to load HDF5 library from:\n\t%s", inputUrl.toString()));

try {

final File temp = File.createTempFile(FilenameUtils.getBaseName(resourcePath),

"." + FilenameUtils.getExtension(resourcePath), tempDir);

FileUtils.copyURLToFile(inputUrl, temp);

temp.deleteOnExit();

logger.debug(String.format("Extracted HDF5 to %s\n", temp.getAbsolutePath()));

final String fileName = temp.getAbsolutePath();

//we use this property to inform H5 where the native library file is

System.setProperty(H5PATH_PROPERTY_KEY, fileName);

final int code = H5.H5open();

if (code < 0) {

logger.warn("could not instantiate the HDF5 library. H5open returned a negative value: " + code);

return false;

}

loaded = true;

return true;

} catch (final HDF5LibraryException | UnsatisfiedLinkError | IOException | SecurityException e) {

logger.warn("could not instantiate the HDF5 Library, due to an exception.", e);

return false;

}

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:53,

示例9: readExchangeSymbols

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

public synchronized String[] readExchangeSymbols(String exchange)

throws EodDataSinkException {

if (!isOpen) {

throw new EodDataSinkException("HDF5 File data sink closed!");

}

Integer exchangeGroupHandle = (Integer) exchangeGroupHandleMap

.get(exchange);

String[] symbols = null;

try {

if (exchangeGroupHandle == null) {

exchangeGroupHandle = H5.H5Gopen(fileHandle, exchange,

HDF5Constants.H5P_DEFAULT);

exchangeGroupHandleMap.put(exchange, exchangeGroupHandle);

}

final H5L_iterate_cb iter_cb = new H5L_iter_callbackT();

final opdata od = new opdata();

@SuppressWarnings("unused")

int status = H5.H5Literate(exchangeGroupHandle,

HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE,

0L, iter_cb, od);

symbols = ((H5L_iter_callbackT) iter_cb).getSymbols();

if (symbols == null || symbols.length <= 0) {

throw new EodDataSinkException(

"Couldn't find any symbols for this exchange.");

}

} catch (HDF5LibraryException lex) {

StringBuffer messageBuffer = new StringBuffer();

messageBuffer.append("Failed to iterate over exchanges ");

messageBuffer.append(exchange);

messageBuffer.append(" ]");

EodDataSinkException e = new EodDataSinkException(

messageBuffer.toString());

e.initCause(lex);

throw e;

}

return symbols;

}

開發者ID:jsr38,項目名稱:ds3,代碼行數:44,

示例10: Hdf5ExchangeDatatype

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

Hdf5ExchangeDatatype() throws EodDataSinkException {

try {

codeDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(codeDatatypeHandle, EXCHANGE_DATATYPE_SIZE_CODE);

nameDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(nameDatatypeHandle, EXCHANGE_DATATYPE_SIZE_NAME);

countryDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(countryDatatypeHandle, EXCHANGE_DATATYPE_SIZE_COUNTRY);

currencyDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(currencyDatatypeHandle, EXCHANGE_DATATYPE_SIZE_CURRENCY);

suffixDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(suffixDatatypeHandle, EXCHANGE_DATATYPE_SIZE_SUFFIX);

timezoneDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_C_S1);

H5.H5Tset_size(timezoneDatatypeHandle, EXCHANGE_DATATYPE_SIZE_TIMEZONE);

isIntradayDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_STD_I32LE);

//intradayStartDateDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_STD_U64BE);

intradayStartDateDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_UNIX_D64LE);

hasIntradayProductDatatypeHandle = H5.H5Tcopy(HDF5Constants.H5T_STD_I32LE);

exchangeDatatypeHandle = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, EXCHANGE_DATATYPE_SIZE);

if (exchangeDatatypeHandle >= 0) {

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_CODE, EXCHANGE_DATATYPE_OFFSET_CODE, codeDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_NAME, EXCHANGE_DATATYPE_OFFSET_NAME, nameDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_COUNTRY, EXCHANGE_DATATYPE_OFFSET_COUNTRY, countryDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_CURRENCY, EXCHANGE_DATATYPE_OFFSET_CURRENCY, currencyDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_SUFFIX, EXCHANGE_DATATYPE_OFFSET_SUFFIX, suffixDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_TIMEZONE, EXCHANGE_DATATYPE_OFFSET_TIMEZONE, timezoneDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_ISINTRADAY, EXCHANGE_DATATYPE_OFFSET_ISINTRADAY, isIntradayDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_INTRADAYSTARTDATE, EXCHANGE_DATATYPE_OFFSET_INTRADAYSTARTDATE, intradayStartDateDatatypeHandle);

H5.H5Tinsert(exchangeDatatypeHandle, EXCHANGE_DATATYPE_NAME_HASINTRADAYPRODUCT, EXCHANGE_DATATYPE_OFFSET_HASINTRADAYPRODUCT, hasIntradayProductDatatypeHandle);

}

else {

throw new EodDataSinkException("Unable to create exchange datatype.");

}

}

catch (HDF5LibraryException ex) {

logger.error(ex);

throw new EodDataSinkException("Unable to create exchange datatype.");

}

}

開發者ID:jsr38,項目名稱:ds3,代碼行數:58,

示例11: readDataset

​點讚 2

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Dataset read template.

*

*

* Reads the dataset located at the path provided, using the input datasetReader lambda.

*

*

*

* This method takes care of allocating HDF5 data structures (Dataset, DataType and DataSpace)

* and freeing them after the data has been read by the lambda provided.

*

*

*

* This method will attempt the closure of resources in the event that any exception occurred within

* the provided lambda.

*

*

*

* The data-reading lambda may throw exceptions such as {@link HDF5LibException} or {@link HDF5LibraryException}

* to indicate issues with

* the data (wrong type, wrong dimensions, etc.).

*

*

* @param fullPath the dataset full path.

* @param datasetReader the actual reading operation implementation.

* @param the return data-type.

* @return whatever {@code datasetReader} provided may return.

* @throws IllegalArgumentException if either {@code fullPath} or {@code datasetReader} is {@code null}.

* @throws HDF5LibException if there is any error when reading the data, for example exceptions thrown by {@code datasetReader} or

* the HDF5 library.

*/

private T readDataset(final String fullPath, final DatasetReader datasetReader) {

if (fullPath == null) {

throw new IllegalArgumentException("the path cannot be null");

}

checkIsOpen();

int typeId = -1;

int dataSetId = -1;

int dataSpaceId = -1;

try {

dataSetId = openDataset(fullPath);

typeId = openType(fullPath, dataSetId);

dataSpaceId = openDataSpace(fullPath, dataSetId);

final int dimNum = H5.H5Sget_simple_extent_ndims(dataSpaceId);

final long[] dimensions = new long[dimNum];

H5.H5Sget_simple_extent_dims(dataSpaceId, dimensions, null);

return datasetReader.apply(dataSetId,typeId,dimensions);

} catch (final HDF5LibraryException ex) {

throw new HDF5LibException(String.format("exception when reading from data-set '%s' in file '%s': %s", fullPath, file, ex.getMessage()), ex);

} finally {

closeResources(fullPath, typeId, dataSetId, dataSpaceId);

}

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:54,

示例12: openDataSpace

​點讚 1

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Opens a HDF5 DataSpace.

*

* @param fullPath dataset full path.

* @param dataSetId dataset id.

* @return the dataSpace id.

* @throws HDF5LibraryException if there was some error thrown by the HDF5 library.

* @throws HDF5LibException if the HDF5 library returned a invalid dataSpace id indicating some kind of issue.

*/

private int openDataSpace(final String fullPath, final int dataSetId) throws HDF5LibraryException {

final int dataSpaceId = H5.H5Dget_space(dataSetId);

if (dataSpaceId <= 0) {

throw new HDF5LibException(

String.format("getting the data-space of data-set '%s' in file '%s' resulted in code: %d", fullPath, file, dataSpaceId));

}

return dataSpaceId;

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:18,

示例13: openType

​點讚 1

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Opens a HDF5 dataType.

*

* @param fullPath dataset full path.

* @param dataSetId dataset id.

* @return the dataType id.

* @throws HDF5LibraryException if there was some error thrown by the HDF5 library.

* @throws HDF5LibException if the HDF5 library returned a invalid dataType id indicating some kind of issue.

*/

private int openType(final String fullPath, final int dataSetId) throws HDF5LibraryException {

final int typeId = H5.H5Dget_type(dataSetId);

if (typeId <= 0) {

throw new HDF5LibException(

String.format("getting the type of data-set '%s' in file '%s' resulted in code: %d", fullPath, file, typeId));

}

return typeId;

}

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:18,

示例14: apply

​點讚 1

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //導入依賴的package包/類

/**

* Reads and returns the data in the underlying HDF5 file given its data-set id, type-id and dimensions.

* @param dataSetId the target data-set.

* @param typeId the target data-set's type.

* @param dimensions the dimensions of the data-set.

* @return might be {@code null}, is up to the implementation.

* @throws HDF5LibraryException forwarding errors originated in the HD5F library.

* @throws HDF5LibException for any exceptional circumstance that make the returned value invalid (e.g. unexpected

* data-type or dimensions).

*/

T apply(int dataSetId, int typeId, long[] dimensions) throws HDF5LibraryException;

開發者ID:broadinstitute,項目名稱:hdf5-java-bindings,代碼行數:12,

注:本文中的ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值