当前位置: 首页>>代码示例>>Java>>正文


Java HDF5LibraryException类代码示例

本文整理汇总了Java中ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException的典型用法代码示例。如果您正苦于以下问题:Java HDF5LibraryException类的具体用法?Java HDF5LibraryException怎么用?Java HDF5LibraryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HDF5LibraryException类属于ncsa.hdf.hdf5lib.exceptions包,在下文中一共展示了HDF5LibraryException类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

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,代码来源:HDF5File.java

示例2: readExchanges

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //导入依赖的package包/类
public synchronized Set<String> 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<String>(Arrays.asList(exchanges));
	}
 
开发者ID:jsr38,项目名称:ds3,代码行数:32,代码来源:Hdf5EodDataSink.java

示例3: close

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //导入依赖的package包/类
/**
 * Flush and close this file reader.
 *
 * <p>
 *     Further file read operations will result in a {@link IllegalStateException}.
 * </p>
 */
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,代码来源:HDF5File.java

示例4: flush

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,代码来源:HDF5File.java

示例5: openDataset

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,代码来源:HDF5File.java

示例6: findOutGroupChildType

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //导入依赖的package包/类
/**
 * Returns the type of a group child given.
 * <p>
 * Type constants are listed in {@link HDF5Constants}, eg.:
 * <ul>
 *     <li>{@link HDF5Constants#H5G_GROUP H5G_GROUP} indicate that the child is another group</li>
 *     <li>{@link HDF5Constants#H5G_DATASET H5G_DATASET} indicate that the child is a dataset...</li>
 * </ul>
 *
 * </p>
 * {@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,代码来源:HDF5File.java

示例7: basicTypeCopyIdSupplier

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,代码来源:HDF5File.java

示例8: loadLibrary

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //导入依赖的package包/类
/**
 * Checks whether HDF5 is supported in the current system.
 * <p>
 *     This method won't result in an exception if HDF5 is not currently supported, just return {@code false}.
 * </p>
 * <p>
 *     This method will load the corresponding HDF5 library for further use if available.
 * </p>
 *
 * @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,代码来源:HDF5Library.java

示例9: readExchangeSymbols

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,代码来源:Hdf5EodDataSink.java

示例10: Hdf5ExchangeDatatype

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,代码来源:Hdf5ExchangeDatatype.java

示例11: readDataset

import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException; //导入依赖的package包/类
/**
 * Dataset read template.
 *
 * <p>
 *     Reads the dataset located at the path provided, using the input datasetReader lambda.
 * </p>
 *
 * <p>
 *     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.
 * </p>
 *
 * <p>
 *     This method will attempt the closure of resources in the event that any exception occurred within
 *     the provided lambda.
 * </p>
 *
 * <p>
 *     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.).
 * </p>
 *
 * @param fullPath the dataset full path.
 * @param datasetReader the actual reading operation implementation.
 * @param <T> 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> T readDataset(final String fullPath, final DatasetReader<T> 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,代码来源:HDF5File.java

示例12: openDataSpace

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,代码来源:HDF5File.java

示例13: openType

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,代码来源:HDF5File.java

示例14: apply

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,代码来源:HDF5File.java


注:本文中的ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。