congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
MappedBytes
Code IndexAdd Tabnine to your IDE (free)

How to use
MappedBytes
in
net.openhft.chronicle.bytes

Best Java code snippets using net.openhft.chronicle.bytes.MappedBytes (Showing top 20 results out of 315)

origin: OpenHFT/Chronicle-Queue

@NotNull
@Override
public String dump() {
  MappedBytes bytes = MappedBytes.mappedBytes(mappedFile);
  try {
    bytes.readLimit(bytes.realCapacity());
    return Wires.fromSizePrefixedBlobs(bytes);
  } finally {
    bytes.release();
  }
}
origin: OpenHFT/Chronicle-Queue

long address = bytes.addressForWrite(bytes.writePosition());
long bstart = bytes.start();
long bcap = bytes.realCapacity();
long canWrite = bcap - (bytes.writePosition() - bstart);
long lengthCount = batchAppender.writeMessages(address, canWrite, writeCount);
bytes.writeSkip((int) lengthCount);
lastIndex += lengthCount >> 32;
count += lengthCount >> 32;
origin: OpenHFT/Chronicle-Queue

public synchronized LongValue acquireValueFor(CharSequence key, long defaultValue) { // TODO Change to ThreadLocal values if performance is a problem.
  StringBuilder sb = Wires.acquireStringBuilder();
  mappedBytes.reserve();
  try {
    mappedBytes.readPosition(0);
    mappedBytes.readLimit(mappedBytes.realCapacity());
    while (mappedWire.readDataHeader()) {
      int header = mappedBytes.readVolatileInt();
      if (Wires.isNotComplete(header))
        break;
      long readPosition = mappedBytes.readPosition();
      int length = Wires.lengthOf(header);
      ValueIn valueIn = mappedWire.readEventName(sb);
        return valueIn.int64ForBinding(null);
      mappedBytes.readPosition(readPosition + length);
    int safeLength = Maths.toUInt31(mappedBytes.realCapacity() - mappedBytes.readPosition());
    mappedBytes.writeLimit(mappedBytes.realCapacity());
    mappedBytes.writePosition(mappedBytes.readPosition());
    long pos = recovery.writeHeader(mappedWire, safeLength, timeoutMS, null, null);
    LongValue longValue = wireType.newLongReference().get();
    mappedBytes.release();
origin: OpenHFT/Chronicle-Queue

private static void dumpFile(@NotNull File file, @NotNull PrintStream out, long upperLimit) {
  Bytes<ByteBuffer> buffer = Bytes.elasticByteBuffer();
  try {
    MappedBytes bytes = MappedBytes.mappedBytes(file, 4 << 20, OS.pageSize(), !OS.isWindows());
    bytes.readLimit(bytes.realCapacity());
    StringBuilder sb = new StringBuilder();
    WireDumper dumper = WireDumper.of(bytes);
    while (bytes.readRemaining() >= 4) {
      sb.setLength(0);
      boolean last = dumper.dumpOne(sb, buffer);
      if (bytes.readPosition() > upperLimit) {
        out.println("# limit reached.");
        return;
origin: OpenHFT/Chronicle-Queue

dir.mkdir();
@NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700101-02" + SingleChronicleQueue.SUFFIX), ChronicleQueue.TEST_BLOCK_SIZE * 2);
@NotNull Wire wire = new BinaryWire(bytes);
try (DocumentContext dc = wire.writingDocument(true)) {
    "    lastIndex: 0\n" +
    "  }\n" +
    "}\n", Wires.fromSizePrefixedBlobs(bytes.readPosition(0)));
bytes.release();
origin: net.openhft/chronicle-bytes

public Bytes<Void> appendUtf8(CharSequence cs, int start, int length)
    throws BufferOverflowException, IllegalArgumentException {
  assert singleThreadedAccess();
  long pos = writePosition();
  writeCheckOffset(pos, 0);
  if (!(cs instanceof String) || pos + length * 3 + 5 >= safeLimit()) {
    super.appendUtf8(cs, start, length);
    return this;
    long address = addressForWrite(pos);
    Memory memory = OS.memory();
    int i = 0;
        byte c = bytes[i + start];
        if (c > 127) {
          writeSkip(i);
          break non_ascii;
      writeSkip(length);
      return this;
      appendUtf8(c);
    long address = addressForWrite(pos);
    Memory memory = OS.memory();
    int i = 0;
        char c = chars[i + start];
origin: OpenHFT/Chronicle-Queue

  long start1 = System.currentTimeMillis();
  String filename = baseDir + "/" + count++;
  queues[i] = MappedBytes.mappedBytes(filename, pagesPer10Second * (4 << 10));
  long time1 = System.currentTimeMillis() - start1;
  if (time1 > 20)
for (int i = 0; i < pagesPer10Second; i++) {
  for (MappedBytes bytes : queues) {
    bytes.writeLong(i * (4 << 10), i);
  bytes.release();
origin: OpenHFT/Chronicle-Queue

/**
 * @return creates a new instance of mapped bytes, because, for example the tailer and appender
 * can be at different locations.
 */
@NotNull
@Override
public MappedBytes bytes() {
  return MappedBytes.mappedBytes(mappedFile);
}
origin: OpenHFT/Chronicle-Queue

private void removeEOF(Path path) throws IOException {
  long blockSize = 64 << 10;
  long chunkSize = OS.pageAlign(blockSize);
  long overlapSize = OS.pageAlign(blockSize / 4);
  final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
  mappedBytes.reserve();
  try {
    final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
    final Bytes<?> bytes = wire.bytes();
    bytes.readLimit(bytes.capacity());
    bytes.readSkip(4);
    // move past header
    try (final SingleChronicleQueueStore qs = loadStore(wire)) {
      assertNotNull(qs);
      long l = qs.writePosition();
      long len = Wires.lengthOf(bytes.readVolatileInt(l));
      long eofOffset = l + len + 4L;
      bytes.writePosition(eofOffset);
      bytes.writeInt(0);
    }
  } finally {
    mappedBytes.release();
  }
}
origin: net.openhft/chronicle-bytes

@NotNull
@Override
public Bytes<Void> append8bit(@NotNull CharSequence cs, int start, int end)
    throws IllegalArgumentException, BufferOverflowException, BufferUnderflowException,
    IndexOutOfBoundsException {
  assert singleThreadedAccess();
  // check the start.
  long pos = writePosition();
  writeCheckOffset(pos, 0);
  if (!(cs instanceof String) || pos + (end - start) * 3 + 5 >= safeLimit()) {
    return super.append8bit(cs, start, end);
  }
  return append8bit0((String) cs, start, end - start);
}
origin: net.openhft/chronicle-bytes

@NotNull
private MappedBytes append8bit0(@NotNull String s, int start, int length) throws BufferOverflowException {
  assert singleThreadedAccess();
  if (Jvm.isJava9Plus()) {
    byte[] bytes = extractBytes(s);
    long address = addressForWrite(writePosition());
    Memory memory = bytesStore().memory;
    int i = 0;
    for (; i < length - 3; i += 4) {
      memory.writeByte(address++, c);
    writeSkip(length);
  } else {
    char[] chars = extractChars(s);
    long address = addressForWrite(writePosition());
    Memory memory = bytesStore().memory;
    int i = 0;
    for (; i < length - 3; i += 4) {
      memory.writeByte(address++, (byte) c);
    writeSkip(length);
origin: net.openhft/chronicle-bytes

@NotNull
@Override
public Bytes<Void> readPositionRemaining(long position, long remaining) throws BufferUnderflowException {
  long limit = position + remaining;
  acquireNextByteStore(position, true);
  if (writeLimit < limit)
    writeLimit(limit);
  boolean debug = false;
  assert debug = true;
  if (debug)
    readLimit(limit);
  else
    uncheckedWritePosition(limit);
  return readPosition(position);
}
origin: net.openhft/chronicle-bytes

public long rawCopy(@NotNull BytesStore bytes, long offset, long length)
    throws BufferOverflowException, BufferUnderflowException {
  assert length < safeCopySize();
  this.acquireNextByteStore(writePosition(), false);
  long len = Math.min(writeRemaining(), Math.min(bytes.readRemaining(), length));
  if (len > 0) {
    OS.memory().copyMemory(bytes.addressForRead(offset), addressForWrite(writePosition()), len);
    uncheckedWritePosition(writePosition() + len);
  }
  return len;
}
origin: OpenHFT/Chronicle-Queue

dir.mkdir();
@NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700101" + SingleChronicleQueue.SUFFIX), ChronicleQueue.TEST_BLOCK_SIZE);
@NotNull Wire wire = new BinaryWire(bytes);
try (DocumentContext dc = wire.writingDocument(true)) {
bytes.release();
try (@NotNull ChronicleQueue queue = binary(dir)
    .rollCycle(RollCycles.TEST4_DAILY)
origin: OpenHFT/Chronicle-Queue

static File getFile(MappedBytes bytes) {
  if (bytes == null)
    return new File("none");
  MappedFile mappedFile = bytes.mappedFile();
  assert (mappedFile != null);
  File file = mappedFile.file();
  assert (file != null);
  return file;
}
origin: OpenHFT/Chronicle-Queue

private void onCleanup() {
  mappedBytes.release();
}
origin: OpenHFT/Chronicle-Queue

@Test
public void testInvalidFile() throws FileNotFoundException {
  @NotNull File dir = new File(OS.TARGET + "/deleteme-" + System.nanoTime());
  dir.mkdir();
  try (@NotNull MappedBytes bytes = MappedBytes.mappedBytes(new File(dir, "19700102" + SingleChronicleQueue.SUFFIX), 64 << 10)) {
    bytes.write8bit("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
    try (@NotNull RollingChronicleQueue queue = binary(dir)
        .rollCycle(RollCycles.TEST4_DAILY)
        .testBlockSize()
        .build()) {
      assertEquals(1, queue.firstCycle());
      assertEquals(1, queue.lastCycle());
      try {
        @NotNull ExcerptTailer tailer = queue.createTailer();
        tailer.toEnd();
        fail();
      } catch (Exception e) {
        assertEquals("java.io.StreamCorruptedException: Unexpected magic number 783f3c37",
            e.toString());
      }
    }
  }
  System.gc();
  try {
    IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath());
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: net.openhft/chronicle-bytes

private synchronized void acquireNextByteStore0(final long offset, final boolean set) {
  @Nullable BytesStore oldBS = this.bytesStore;
  try {
    @Nullable BytesStore newBS = mappedFile.acquireByteStore(offset);
    this.bytesStore = newBS;
    oldBS.release();
  } catch (@NotNull IOException | IllegalStateException | IllegalArgumentException e) {
    @NotNull BufferOverflowException boe = new BufferOverflowException();
    boe.initCause(e);
    throw boe;
  }
  if (set) {
    if (writeLimit() < readPosition)
      writeLimit(readPosition);
    if (readLimit() < readPosition)
      readLimit(readPosition);
    readPosition = offset;
  }
}
origin: net.openhft/chronicle-bytes

@NotNull
@Override
public Bytes<Void> readSkip(long bytesToSkip)
    throws BufferUnderflowException {
  if (readPosition + bytesToSkip > readLimit()) throw new BufferUnderflowException();
  long check = bytesToSkip >= 0 ? this.readPosition : this.readPosition + bytesToSkip;
  if (bytesStore instanceof NoBytesStore ||
      bytesToSkip != (int) bytesToSkip ||
      !bytesStore.inside(readPosition, (int) bytesToSkip)) {
    acquireNextByteStore0(check, false);
  }
  this.readPosition += bytesToSkip;
  return this;
}
origin: net.openhft/chronicle-bytes

protected MappedBytes(@NotNull MappedFile mappedFile, String name) throws IllegalStateException {
  super(NoBytesStore.noBytesStore(), NoBytesStore.noBytesStore().writePosition(),
      NoBytesStore.noBytesStore().writeLimit(), name);
  this.mappedFile = reserve(mappedFile);
  this.backingFileIsReadOnly = !mappedFile.file().canWrite();
  assert !mappedFile.isClosed();
  clear();
}
net.openhft.chronicle.bytesMappedBytes

Javadoc

Bytes to wrap memory mapped data.

NOTE These Bytes are single Threaded as are all Bytes.

Most used methods

  • mappedBytes
  • addressForWrite
  • readLimit
  • readPosition
  • release
  • reserve
  • writePosition
  • writeSkip
  • mappedFile
  • readRemaining
  • realCapacity
  • start
  • realCapacity,
  • start,
  • writeLimit,
  • writeLong,
  • <init>,
  • acquireNextByteStore,
  • acquireNextByteStore0,
  • append8bit0,
  • appendUtf8,
  • bytesStore

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • startActivity (Activity)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Sublime Text for Python
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now