/** * Check that file exists, open file, and return MappedByteBuffer for entire file * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for any exceptions * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile(final File location, final String descriptionLabel) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size()); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
/** * Check that file exists, open file, and return MappedByteBuffer for only region specified * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for an exceptions * @param offset offset to start mapping at * @param length length to map region * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile( final File location, final String descriptionLabel, final long offset, final long length) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, offset, length); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
private void openFile(final File file) { checkFileExists(file, file.getName()); try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); channel = randomAccessFile.getChannel(); map(channel.size()); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } }
/** * Check that file exists, open file, and return MappedByteBuffer for only region specified * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for an exceptions * @param offset offset to start mapping at * @param length length to map region * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile( final File location, final String descriptionLabel, final long offset, final long length) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, offset, length); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
/** * Check that file exists, open file, and return MappedByteBuffer for entire file * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for any exceptions * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile(final File location, final String descriptionLabel) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size()); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
/** * Check that file exists, open file, and return MappedByteBuffer for entire file * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for any exceptions * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile(final File location, final String descriptionLabel) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, 0, channel.size()); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }
/** * Check that file exists, open file, and return MappedByteBuffer for only region specified * <p> * The file itself will be closed, but the mapping will persist. * * @param location of the file to map * @param descriptionLabel to be associated for an exceptions * @param offset offset to start mapping at * @param size length to map region * @return {@link java.nio.MappedByteBuffer} for the file */ public static MappedByteBuffer mapExistingFile( final File location, final String descriptionLabel, final long offset, final long size) { checkFileExists(location, descriptionLabel); MappedByteBuffer mappedByteBuffer = null; try (RandomAccessFile file = new RandomAccessFile(location, "rw"); FileChannel channel = file.getChannel()) { mappedByteBuffer = channel.map(READ_WRITE, offset, size); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return mappedByteBuffer; }