@NotNull @Override public ByteOrder order() { assert buffer != null; return buffer.order(); }
static PinotByteBuffer mapFile(File file, boolean readOnly, long offset, int size, ByteOrder byteOrder) throws IOException { if (readOnly) { try (FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel()) { ByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, offset, size).order(byteOrder); return new PinotByteBuffer(buffer, true, false); } } else { try (FileChannel fileChannel = new RandomAccessFile(file, "rw").getChannel()) { ByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, offset, size).order(byteOrder); return new PinotByteBuffer(buffer, true, true); } } }
public static MappedByteBuffer getMap(@NotNull FileChannel fileChannel, long start, int size) throws IOException { for (int i = 1; ; i++) { try { // long startTime = System.nanoTime(); @SuppressWarnings("UnnecessaryLocalVariable") MappedByteBuffer map = fileChannel.map(FileChannel.MapMode.READ_WRITE, start, size); map.order(ByteOrder.nativeOrder()); // long time = System.nanoTime() - startTime; // System.out.printf("Took %,d us to map %,d MB%n", time / 1000, size / 1024 / 1024); // System.out.println("Map size: "+size); return map; } catch (IOException e) { if (e.getMessage() == null || !e.getMessage().endsWith("user-mapped section open")) { throw e; } if (i < 10) //noinspection CallToThreadYield Thread.yield(); else try { //noinspection BusyWait Thread.sleep(1); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); throw e; } } } }
@Nullable @Override public MappedMemory acquireDataBuffer(long startPosition) { if (startPosition >= MAX_VIRTUAL_ADDRESS) return throwByteOrderIsIncorrect(); try { MappedMemory mbb = dataCache.acquire(startPosition >>> dataBitSize); mbb.buffer().order(ByteOrder.nativeOrder()); return mbb; } catch (IOException e) { throw new IllegalStateException(e); } }
@NotNull protected MappedMemory acquireIndexBuffer(long startPosition) { if (startPosition >= MAX_VIRTUAL_ADDRESS) throwByteOrderIsIncorrect(); try { // long start = System.nanoTime(); MappedMemory mbb = indexCache.acquire(startPosition >>> indexBitSize); // long time = System.nanoTime() - start; // System.out.println(Thread.currentThread().getName()+": map "+time); mbb.buffer().order(byteOrder); return mbb; } catch (IOException e) { throw new IllegalStateException(e); } }
directoryMap.order(ByteOrder.LITTLE_ENDIAN);
directoryMap.order(ByteOrder.LITTLE_ENDIAN);
public ELFHeader(MappedByteBuffer fmap) throws IllegalArgumentException { if (fmap.get(ELFIdentification.EI_MAG0.value()) != 0x7f || fmap.get(ELFIdentification.EI_MAG1.value()) != 'E' || fmap.get(ELFIdentification.EI_MAG2.value()) != 'L' || fmap.get(ELFIdentification.EI_MAG3.value()) != 'F') { throw new IllegalArgumentException("Not an ELF file"); } ei_class = EI_Class.valueOf(fmap.get(ELFIdentification.EI_CLASS.value())); ei_data = EI_Data.valueOf(fmap.get(ELFIdentification.EI_DATA.value())); ei_version = fmap.get(ELFIdentification.EI_VERSION.value()); if (ei_data == EI_Data.ELFDATA2LSB) { fmap.order(ByteOrder.LITTLE_ENDIAN); } else { fmap.order(ByteOrder.BIG_ENDIAN); } fmap.position(ELFIdentification.EI_NIDENT.value()); e_type = E_Type.valueOf(fmap.getShort()); e_machine = E_Machine.valueOf(fmap.getShort()); e_version = E_Version.valueOf(fmap.getInt()); e_entry = fmap.getInt(); e_phoff = fmap.getInt(); e_shoff = fmap.getInt(); e_flags = fmap.getInt(); e_ehsize = fmap.getShort(); e_phentsize = fmap.getShort(); e_phnum = fmap.getShort(); e_shentsize = fmap.getShort(); e_shnum = fmap.getShort(); e_shstrndx = fmap.getShort(); }
@Override public RawShadingResult transformToByteBuffer(HgtCache.HgtFileInfo source, int padding) { int axisLength = getAxisLenght(source); int rowLen = axisLength + 1; FileInputStream stream = null; FileChannel channel = null; try { File file = source.getFile(); stream = new FileInputStream(file); channel = stream.getChannel(); MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); map.order(ByteOrder.BIG_ENDIAN); byte[] bytes = convert(map, axisLength, rowLen, padding); return new RawShadingResult(bytes, axisLength, axisLength, padding); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); return null; } finally { if (channel != null) try { channel.close(); } catch (IOException e) { e.printStackTrace(); } if (stream != null) try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } }
@Override public RawShadingResult transformToByteBuffer(HgtCache.HgtFileInfo source, int padding) { int axisLength = getAxisLenght(source); int rowLen = axisLength + 1; FileInputStream stream = null; FileChannel channel = null; try { File file = source.getFile(); stream = new FileInputStream(file); channel = stream.getChannel(); MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); map.order(ByteOrder.BIG_ENDIAN); byte[] bytes = convert(map, axisLength, rowLen, padding, source); return new RawShadingResult(bytes, axisLength, axisLength, padding); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); return null; } finally { if (channel != null) try { channel.close(); } catch (IOException e) { e.printStackTrace(); } if (stream != null) try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } }
/** * Returns the byte-order of this buffer (actually, the order of the first * child buffer; they should all be the same). */ public ByteOrder getByteOrder() { return _buffers[0].order(); }
@NotNull @Override public ByteOrder order() { assert buffer != null; return buffer.order(); }
private MappedByteBuffer createChunk(final long offset, final long size) throws IOException { final MappedByteBuffer map = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, offset, size); map.order(ByteOrder.LITTLE_ENDIAN); return map; }
@Override public void setByteOrder(ByteOrder networkByteOrder) { super.setByteOrder(networkByteOrder); mappedBuffer.order(networkByteOrder); }
public void setByteOrder(ByteOrder networkByteOrder) { super.setByteOrder(networkByteOrder); mappedBuffer.order(networkByteOrder); } }
private synchronized MappedByteBuffer map(long address, long size) throws IOException { long start = System.nanoTime(); MappedByteBuffer buffer = this.fileChannel.map(this.mode.mapValue(), address, size); buffer.order(ByteOrder.nativeOrder()); fileLifecycleListener.onEvent(EventType.MMAP, path, System.nanoTime() - start); return buffer; } }
private synchronized MappedByteBuffer map(long address, long size) throws IOException { long start = System.nanoTime(); MappedByteBuffer buffer = this.fileChannel.map(this.mode.mapValue(),address,size); buffer.order(ByteOrder.nativeOrder()); fileLifecycleListener.onEvent(EventType.MMAP, path, System.nanoTime() - start); return buffer; }
@NonNull public static ByteBuffer mapFile(@NonNull File f, long offset, @NonNull ByteOrder byteOrder) throws IOException { FileInputStream dataFile = new FileInputStream(f); try { FileChannel fc = dataFile.getChannel(); MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, f.length() - offset); buffer.order(byteOrder); return buffer; } finally { dataFile.close(); // this *also* closes the associated channel, fc } }