public void close() { if (buffer != null) { NIOUtilities.clean(buffer, useMemoryMapping); buffer = null; } }
public void clean(Object key, Object object) { MappedByteBuffer buffer = (MappedByteBuffer) object; NIOUtilities.clean(buffer, true); } }
private void closeWriterChannels() throws IOException { if (channel.isOpen()) channel.close(); streamLogger.close(); if (writeBuffer != null) { NIOUtilities.clean(writeBuffer, false); writeBuffer = null; } }
/** * Depending on the type of buffer different cleanup action will be taken: * * <ul> * <li>if the buffer is memory mapped (as per the specified parameter) the effect is the same * as {@link #clean(ByteBuffer)} * <li>if the buffer is not memory mapped it will be returned to the buffer cache * </ul> * * @param buffer * @return */ public static boolean clean(final ByteBuffer buffer, boolean memoryMapped) { if (memoryMapped) { return clean(buffer); } else { if (returnToCache(buffer)) { return true; } else { return clean(buffer); } } }
private void writeHeader() throws IOException { ByteBuffer buffer = NIOUtilities.allocate(HEADER_SIZE); try { buffer.put((byte) 1); buffer.putLong(recordIndex); buffer.putInt(removes); buffer.flip(); channel.write(buffer, 0); } finally { NIOUtilities.clean(buffer, false); } }
public void close() throws IOException { closed = true; if (channel != null && channel.isOpen()) { channel.close(); streamLogger.close(); NIOUtilities.clean(buf, useMemoryMappedBuffer); } this.buf = null; this.content = null; this.channel = null; }
public void close() throws IOException { try { if (buffer != null) { NIOUtilities.clean(buffer, false); } } finally { buffer = null; readChannel.close(); streamLogger.close(); } }
/** Make sure our buffer is of size. */ private void checkShapeBuffer(int size) { if (shapeBuffer.capacity() < size) { if (shapeBuffer != null) NIOUtilities.clean(shapeBuffer, false); shapeBuffer = NIOUtilities.allocate(size); } }
/** * The reader will close itself right after reading the CRS from the prj file, so no actual need * to call it explicitly anymore. * * @throws IOException */ public void close() throws IOException { if (buffer != null) { NIOUtilities.clean(buffer); // will close if a MappedByteBuffer buffer = null; } if (channel.isOpen()) { channel.close(); } } }
void clean() { List<MappingKey> keys = new ArrayList<MappingKey>(buffers.keySet()); for (MappingKey key : keys) { MappedByteBuffer buffer = buffers.remove(key); NIOUtilities.clean(buffer, true); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Removed mapping for " + key.file.getAbsolutePath()); } } }
/** Close the underlying Channels. */ public void close() throws IOException { try { if (shpChannel != null && shpChannel.isOpen()) { shpChannel.close(); shpLogger.close(); } } finally { if (shxChannel != null && shxChannel.isOpen()) { shxChannel.close(); shxLogger.close(); } } shpChannel = null; shxChannel = null; handler = null; if (indexBuffer != null) NIOUtilities.clean(indexBuffer, false); if (shapeBuffer != null) NIOUtilities.clean(shapeBuffer, false); indexBuffer = null; shapeBuffer = null; }
private void readHeader(ReadableByteChannel channel) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(100); try { while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); header = new ShapefileHeader(); header.read(buffer, true); } finally { NIOUtilities.clean(buffer, false); } }
@Override public void clear() { ByteBuffer buffer = get(); NIOUtilities.clean(buffer); super.clear(); }
private void readRecords(ReadableByteChannel channel) throws IOException { check(); int remaining = (header.getFileLength() * 2) - 100; ByteBuffer buffer = NIOUtilities.allocate(remaining); try { buffer.order(ByteOrder.BIG_ENDIAN); while (buffer.remaining() > 0) { channel.read(buffer); } buffer.flip(); int records = remaining / 4; content = new int[records]; IntBuffer ints = buffer.asIntBuffer(); ints.get(content); } finally { NIOUtilities.clean(buffer, false); } }
private void bufferCheck() throws IOException { // remaining is less than record length // compact the remaining data and read again if (useMemoryMappedBuffer) { if (buffer.remaining() < header.getRecordLength()) { // ops, we're dealing with a DBF whose size is > 2GB (and < 4 normally?) FileChannel fc = (FileChannel) channel; int position = buffer.position(); if (fc.size() > position + Integer.MAX_VALUE) { currentOffset = position; } else { currentOffset = fc.size() - Integer.MAX_VALUE; } NIOUtilities.clean(buffer); buffer = fc.map(MapMode.READ_ONLY, currentOffset, Integer.MAX_VALUE); buffer = ((FileChannel) channel) .map(MapMode.READ_ONLY, buffer.position(), Integer.MAX_VALUE); } } else if (buffer.remaining() < header.getRecordLength()) { this.currentOffset += buffer.position(); buffer.compact(); fill(buffer, channel); buffer.position(0); } }
/** * Clean up all resources associated with this reader.<B>Highly recomended.</B> * * @throws IOException If an error occurs. */ public void close() throws IOException { if (channel != null && channel.isOpen()) { channel.close(); streamLogger.close(); } if (buffer != null) { NIOUtilities.clean(buffer, useMemoryMappedBuffer); } buffer = null; channel = null; bytes = null; header = null; row = null; }
/** * Release resources associated with this writer. <B>Highly recommended</B> * * @throws IOException If errors occur. */ public void close() throws IOException { // IANS - GEOT 193, bogus 0x00 written. According to dbf spec, optional // eof 0x1a marker is, well, optional. Since the original code wrote a // 0x00 (which is wrong anyway) lets just do away with this :) // - produced dbf works in OpenOffice and ArcExplorer java, so it must // be okay. // buffer.position(0); // buffer.put((byte) 0).position(0).limit(1); // write(); if (channel != null && channel.isOpen()) { channel.close(); streamLogger.close(); } if (buffer != null) { NIOUtilities.clean(buffer, false); } buffer = null; channel = null; formatter = null; }
if (key.file.equals(file)) { MappedByteBuffer buffer = buffers.remove(key); NIOUtilities.clean(buffer, true); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Removed mapping for " + file.getAbsolutePath());
/** * Clean up any resources. Closes the channel. * * @throws IOException If errors occur while closing the channel. */ public void close() throws IOException { // don't throw NPE on double close if (channel == null) return; try { if (channel.isOpen()) { channel.close(); streamLogger.close(); } NIOUtilities.clean(buffer, useMemoryMappedBuffer); } finally { if (shxReader != null) shxReader.close(); } shxReader = null; channel = null; header = null; }
private void getHeader(ShpFiles shpFiles) throws IOException { ByteBuffer buffer = NIOUtilities.allocate(IndexedFidWriter.HEADER_SIZE); try { ShapefileReader.fill(buffer, readChannel); if (buffer.position() == 0) { done = true; count = 0; return; } buffer.position(0); byte version = buffer.get(); if (version != 1) { throw new IOException( "File is not of a compatible version for this reader or file is corrupt."); } this.count = buffer.getLong(); this.removes = buffer.getInt(); if (removes > getCount() / 2) { URL url = shpFiles.acquireRead(FIX, this); try { URLs.urlToFile(url).deleteOnExit(); } finally { shpFiles.unlockRead(url, this); } } } finally { NIOUtilities.clean(buffer, false); } }