public void close() { if (buffer != null) { NIOUtilities.clean(buffer, useMemoryMapping); buffer = null; } }
public Boolean run() { Boolean success = Boolean.FALSE; try { Method getCleanerMethod = getCleanerMethod(buffer); if (getCleanerMethod != null) { Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null); if (cleaner != null) { Method clean = cleaner.getClass() .getMethod("clean", (Class[]) null); clean.invoke(cleaner, (Object[]) null); success = Boolean.TRUE; } } } catch (Exception e) { // This really is a show stopper on windows if (isLoggable()) { log(e, buffer); } } return success; } });
/** * 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); } } }
Queue<Object> buffers = getBuffers(size); Object sr = null; while ((sr = buffers.poll()) != null) {
/** Allocate some buffers for writing. */ private void allocateBuffers() { writeBuffer = NIOUtilities.allocate(HEADER_SIZE + RECORD_SIZE * 1024); }
public void clean(Object key, Object object) { MappedByteBuffer buffer = (MappedByteBuffer) object; NIOUtilities.clean(buffer, true); } }
public ScrollingBuffer(FileChannel channel, ByteOrder order, boolean useMemoryMapping) throws IOException { this.channel = channel; this.order = order; this.useMemoryMapping = useMemoryMapping; this.bufferStart = channel.position(); if (useMemoryMapping) { this.buffer = channel.map( MapMode.READ_ONLY, channel.position(), channel.size() - channel.position()); this.buffer.order(order); } else { // start with an 8kb buffer this.buffer = NIOUtilities.allocate(8 * 1024); this.buffer.order(order); channel.read(buffer); buffer.flip(); } }
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; }
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); } }
/** * @param requiredSize * @throws IOException */ void refillBuffer(int requiredSize) throws IOException { // compute the actual position up to we have read something long currentPosition = bufferStart + buffer.position(); // if the buffer is not big enough enlarge it if (buffer.capacity() < requiredSize) { int size = buffer.capacity(); while (size < requiredSize) size *= 2; buffer = NIOUtilities.allocate(size); buffer.order(order); } readBuffer(currentPosition); }
private void closeWriterChannels() throws IOException { if (channel.isOpen()) channel.close(); streamLogger.close(); if (writeBuffer != null) { NIOUtilities.clean(writeBuffer, false); writeBuffer = null; } }
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 ByteBuffer ensureCapacity(ByteBuffer buffer, int size, boolean useMemoryMappedBuffer) { // This sucks if you accidentally pass is a MemoryMappedBuffer of size // 80M // like I did while messing around, within moments I had 1 gig of // swap... if (buffer.isReadOnly() || useMemoryMappedBuffer) { return buffer; } int limit = buffer.limit(); while (limit < size) { limit *= 2; } if (limit != buffer.limit()) { // clean up the old buffer and allocate a new one buffer = NIOUtilities.allocate(limit); } return buffer; }
public void close() throws IOException { try { if (buffer != null) { NIOUtilities.clean(buffer, false); } } finally { buffer = null; readChannel.close(); streamLogger.close(); } }
private void init(ShpFiles shpFiles, ReadableByteChannel in) throws IOException { this.typeName = shpFiles.getTypeName() + "."; this.fidBuilder = new StringBuilder(typeName); this.readChannel = in; streamLogger.open(); getHeader(shpFiles); buffer = NIOUtilities.allocate(IndexedFidWriter.RECORD_SIZE * 1024); buffer.position(buffer.limit()); }
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()); } } }