Package com.slytechs.utils.memory

Examples of com.slytechs.utils.memory.BufferBlock


    this.length = total;

    this.buffer = this.allocate(this.length);
    this.partial =
        new BufferBlock(this.buffer, BitBuffer.wrap(this.buffer), 0,
            this.length);

    // Copy contents from all the elements buffer into our large buffer
    for (final ByteBuffer b : buffers) {
      this.buffer.put(b);
View Full Code Here


        this.buffer = buffer;
      }
    }

    this.partial =
        new BufferBlock(this.buffer, BitBuffer.wrap(this.buffer), 0,
            this.length);
  }
View Full Code Here

    this.buffer = this.allocate(this.length);
    this.buffer.put(buffer1);
    this.buffer.put(buffer2);

    this.partial =
        new BufferBlock(this.buffer, BitBuffer.wrap(this.buffer), 0,
            this.length);
  }
View Full Code Here

    this.length = length;
    this.lengthGetter = overrideOffset(lengthGetter);
    this.buffer = this.allocate(length);

    this.partial =
        new BufferBlock(this.buffer, BitBuffer.wrap(this.buffer), 0, length);
  }
View Full Code Here

  private BufferBlock fetchFromChannel(final long regional, final int length,
      FileMode mode, MemoryModel memoryModel) throws IOException {

    final boolean readwrite = mode.isContent();

    BufferBlock block = null;
    ByteBuffer buf;
    final int minimum = pickMinimumSize(regional, length);

    /*
     * Needed to make sure the file is synched. There were some intermittened
     * failures with HardRegionIndexer while it was scanning the entire file
     * without this force. Therefore it must be here. Some portions of the file
     * were lagging with the synch to the physical file.
     */
    channel.force(true);

    switch (memoryModel) {
      case MappedFile:
        final MapMode mapMode = ((readwrite) ? MapMode.READ_WRITE
            : MapMode.READ_ONLY);
        buf = this.channel.map(mapMode, regional, minimum);
        buf.clear();

        block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, buf.capacity());
        block.getByteBuffer().order(this.byteOrder);

        System.gc();

        break;

      case DirectBuffer:
        System.out.flush();

        buf = ByteBuffer.allocateDirect(minimum);
        buf.clear();

        this.channel.position(regional);
        int s = this.channel.read(buf);
        buf.clear();

        buf = BufferUtils.asReadonly(buf);

        block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, s);
        block.getByteBuffer().order(this.byteOrder);

        break;

      case ByteArray:

        buf = ByteBuffer.allocate(minimum);
        buf.clear();

        this.channel.position(regional);
        s = this.channel.read(buf);
        buf.clear();

        buf = BufferUtils.asReadonly(buf);

        block = new BufferBlock(buf, BitBuffer.wrap(buf), regional, s);
        block.getByteBuffer().order(this.byteOrder);

        break;

      default:
        throw new IllegalStateException("Unknown memory model encountered "
View Full Code Here

   * @throws IOException
   */
  private PartialBuffer fetchFromChannelAndCache(long regional, int length,
      MemoryModel memoryModel) throws IOException {

    final BufferBlock partial = fetchFromChannel(regional, length, mode,
        memoryModel);
    partial.reposition(regional, length);

    cache.add(partial);
    globalCache.add(partial);

    return partial;
View Full Code Here

  private void setupBuffer(int cap, ByteBuffer old) {

    this.buffer = ByteBuffer.allocate(cap);
    this.buffer.order(order);
    this.rwBlock = new BufferBlock(this.buffer, null, 0, cap);
    this.buffer.limit(0);

    this.view = BufferUtils.asReadonly(buffer);
    this.roBlock = new BufferBlock(this.view, null, 0, cap);
    this.view.limit(0);

    /*
     * Lastly copy any remnants left in the old view buffer into our new buffer.
     * Typically the header is partially read from the stream then if the length
View Full Code Here

TOP

Related Classes of com.slytechs.utils.memory.BufferBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.