.directBuffer(initialCapacity, maxCapacity);
public CachedSingleFileSystem(String path) throws IOException { this.path = path; File f = new File(path); long length = f.length(); if (length > Integer.MAX_VALUE) { throw new UnsupportedOperationException("Cached file system only supports files of less than 2GB."); } System.out.println(length); try (InputStream is = new BufferedInputStream(new FileInputStream(path))) { byte[] buffer = new byte[64*1024]; this.file = UnpooledByteBufAllocator.DEFAULT.directBuffer((int) length); int read; while ( (read = is.read(buffer)) > 0) { file.writeBytes(buffer, 0, read); } } }
.directBuffer(initialCapacity, maxCapacity);
private UnsafeDirectLittleEndian newDirectBufferL(int initialCapacity, int maxCapacity) { PoolThreadCache cache = threadCache(); PoolArena<ByteBuffer> directArena = cache.directArena; if (directArena != null) { if (initialCapacity > directArena.chunkSize) { // This is beyond chunk size so we'll allocate separately. ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(initialCapacity, maxCapacity); hugeBufferSize.addAndGet(buf.capacity()); hugeBufferCount.incrementAndGet(); // logger.debug("Allocating huge buffer of size {}", initialCapacity, new Exception()); return new AccountedUnsafeDirectLittleEndian(new LargeBuffer(buf), hugeBufferCount, hugeBufferSize); } else { // within chunk, use arena. ByteBuf buf = directArena.allocate(cache, initialCapacity, maxCapacity); if (!(buf instanceof PooledUnsafeDirectByteBuf)) { fail(); } if (!ASSERT_ENABLED) { return new UnsafeDirectLittleEndian((PooledUnsafeDirectByteBuf) buf); } normalBufferSize.addAndGet(buf.capacity()); normalBufferCount.incrementAndGet(); return new AccountedUnsafeDirectLittleEndian((PooledUnsafeDirectByteBuf) buf, normalBufferCount, normalBufferSize); } } else { throw fail(); } }