public ZeroCopyOutputStream(int initialSize, ByteOrder order) { buffer = new NativeBuffer(initialSize, order); memory = buffer.memory(); }
@Override public void close() { if (mLock) physicalMemory.munlock(0, physicalMemory.memory().length()); runCleaner.set(false); Closeables2.closeQuietly(physicalMemory, log); }
public static Stat fstat(FileDescriptor fd) throws IOException { NativeBuffer nativeBuffer = new NativeBuffer(92, ByteOrder.nativeOrder()); try { DirectMemory direct = nativeBuffer.memory(); try { int err = fstat(fdField.getInt(fd), direct.getAddress()); if (err == errstr.indexOf("ENOENT")) { throw new FileNotFoundException("No such file or directory"); } if (err != 0) { throw new IOException("fstat on file descriptor "+fd+" failed with error "+(err < 0 ? "unknown" : errstr.get(err))); } } catch (IllegalAccessException e) { throw Throwables.propagate(e); } return new Stat(direct); } finally { nativeBuffer.close(); } }
public static Stat stat(String file) throws IOException { NativeBuffer nativeBuffer = new NativeBuffer(92, ByteOrder.nativeOrder()); try { DirectMemory direct = nativeBuffer.memory(); int err = stat(file, direct.getAddress()); if (err != 0) { if (err == errstr.indexOf("ENOENT")) { throw new FileNotFoundException("No such file or directory: "+file); } throw new IOException("stat on path "+file+" failed with error "+(err < 0 ? "unknown" : errstr.get(err))); } return new Stat(direct); } finally { nativeBuffer.close(); } }
public static Stat lstat(String file) throws IOException { NativeBuffer nativeBuffer = new NativeBuffer(92, ByteOrder.nativeOrder()); try { DirectMemory direct = nativeBuffer.memory(); int err = lstat(file, direct.getAddress()); if (err == errstr.indexOf("ENOENT")) { throw new FileNotFoundException("No such file or directory: "+file); } if (err != 0) { throw new IOException("stat on path "+file+" failed with error "+(err < 0 ? "unknown" : errstr.get(err))); } return new Stat(direct); } finally { nativeBuffer.close(); } }
private NativeBuffer createNewAndClose(long newSize) { final NativeBuffer ret = new NativeBuffer(newSize, memory.getOrder()); ret.memory().putBytes(0, memory, 0, Math.min(memory.length(), newSize)); closeQuietly(this); return ret; }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { if (off < 0 || len < 0 || off+len > b.length) { throw new IndexOutOfBoundsException(); } if (currentAddress + len > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); write(b, off, len); } else { memory.putBytes(currentAddress, b, off, len); currentAddress+=len; } }
public void writeBoolean(final boolean v) throws IOException { if (currentAddress + 1 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeBoolean(v); } else { memory.putByte(currentAddress, (byte)(v ? 1 : 0)); currentAddress++; } }
activePages = new PageTableEntry[(int)(physicalSize >>> PAGE_BITS)]; for (long i = 0; i < physicalSize; i += PAGE_SIZE) { freePages.add(physicalMemory.memory().slice(i, PAGE_SIZE));
public void writeByte(final int v) throws IOException { if (currentAddress + 1 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeByte(v); } else { memory.putByte(currentAddress, (byte)v); currentAddress++; } }
public void writeShort(final int v) throws IOException { if (currentAddress + 2 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeShort(v); } else { memory.putShort(currentAddress, (short)v); currentAddress+=2; } }
public void writeChar(final int v) throws IOException { if (currentAddress + 2 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeChar(v); } else { memory.putChar(currentAddress, (char)v); currentAddress+=2; } }
public void writeInt(final int v) throws IOException { if (currentAddress + 4 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeInt(v); } else { memory.putInt(currentAddress, v); currentAddress+=4; } }
public void writeFloat(final float v) throws IOException { if (currentAddress + 4 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeFloat(v); } else { memory.putFloat(currentAddress, v); currentAddress+=4; } }
public void writeLong(final long v) throws IOException { if (currentAddress + 8 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeLong(v); } else { memory.putLong(currentAddress, v); currentAddress+=8; } }
public void writeDouble(final double v) throws IOException { if (currentAddress + 8 > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); writeDouble(v); } else { memory.putDouble(currentAddress, v); currentAddress+=8; } }
final IntArray intArray = offsets.memory().intArray(0, r.getNumDocs()); final ZeroCopyOutputStream valuesFileOut = new ZeroCopyOutputStream(); final CountingOutputStream counter = new CountingOutputStream(new BufferedOutputStream(valuesFileOut));