Package java.nio.channels

Examples of java.nio.channels.FileChannel.position()


        valueLocation += 4; // key size
        valueLocation += 4; // value size
        valueLocation += keyBytesLength; // key

        // read
        int read = valueBytes.readFromChannel(fileChannel.position(valueLocation), valueBytesLength);
        if(read < valueBytesLength) throw new IOException("Expected " + valueBytesLength + " but found " + read + " bytes");

        // done
        return valueBytes;
    }
View Full Code Here


          blockIn instanceof FileInputStream) {
       
        FileChannel fileChannel = ((FileInputStream)blockIn).getChannel();
       
        // blockInPosition also indicates sendChunks() uses transferTo.
        blockInPosition = fileChannel.position();
        streamForSendChunks = baseStream;
       
        // assure a mininum buffer size.
        maxChunksPerPacket = (Math.max(BUFFER_SIZE,
                                       MIN_BUFFER_WITH_TRANSFERTO)
View Full Code Here

  @Override // FsDatasetSpi
  public void adjustCrcChannelPosition(ExtendedBlock b, ReplicaOutputStreams streams,
      int checksumSize) throws IOException {
    FileOutputStream file = (FileOutputStream)streams.getChecksumOut();
    FileChannel channel = file.getChannel();
    long oldPos = channel.position();
    long newPos = oldPos - checksumSize;
    if (LOG.isDebugEnabled()) {
      LOG.debug("Changing meta file offset of block " + b + " from " +
          oldPos + " to " + newPos);
    }
View Full Code Here

    long newPos = oldPos - checksumSize;
    if (LOG.isDebugEnabled()) {
      LOG.debug("Changing meta file offset of block " + b + " from " +
          oldPos + " to " + newPos);
    }
    channel.position(newPos);
  }

  //
  // REMIND - mjc - eventually we should have a timeout system
  // in place to clean up block files left by abandoned clients.
View Full Code Here

        }
        FileChannel fc = null;
        try {
            if (getEndpoint().isAppend()) {
                fc = new RandomAccessFile(file, "rw").getChannel();
                fc.position(fc.size());
            }
            else {
                fc = new FileOutputStream(file).getChannel();
            }
            int size = getEndpoint().getBufferSize();
View Full Code Here

     * eg. it should append or override any existing content.
     */
    private FileChannel prepareOutputFileChannel(File target) throws IOException {
        if (endpoint.getFileExist() == GenericFileExist.Append) {
            FileChannel out = new RandomAccessFile(target, "rw").getChannel();
            return out.position(out.size());
        }
        return new FileOutputStream(target).getChannel();
    }
}
View Full Code Here

        // if(capacity == 0)
        // {
        // throw new IOException("empty file");
        // }
        //
        if ((ch.position() + size) > ch.size()) {
            // TODO fix the bug
            LOG.fatal("getByteBuffer: FATAL: size too big. size=" + size + " position=" +
                    ch.position() + " channel.size=" + ch.size());
            size = (int) (ch.size() - ch.position());
        }
View Full Code Here

        // }
        //
        if ((ch.position() + size) > ch.size()) {
            // TODO fix the bug
            LOG.fatal("getByteBuffer: FATAL: size too big. size=" + size + " position=" +
                    ch.position() + " channel.size=" + ch.size());
            size = (int) (ch.size() - ch.position());
        }

        LOG.debug("getByteBuffer: pos=" + ch.position() + " size=" + size + " channel.size=" +
                ch.size());
View Full Code Here

        //
        if ((ch.position() + size) > ch.size()) {
            // TODO fix the bug
            LOG.fatal("getByteBuffer: FATAL: size too big. size=" + size + " position=" +
                    ch.position() + " channel.size=" + ch.size());
            size = (int) (ch.size() - ch.position());
        }

        LOG.debug("getByteBuffer: pos=" + ch.position() + " size=" + size + " channel.size=" +
                ch.size());
        ByteBuffer bb = ch.map(MapMode.READ_ONLY, ch.position(), size);
View Full Code Here

            LOG.fatal("getByteBuffer: FATAL: size too big. size=" + size + " position=" +
                    ch.position() + " channel.size=" + ch.size());
            size = (int) (ch.size() - ch.position());
        }

        LOG.debug("getByteBuffer: pos=" + ch.position() + " size=" + size + " channel.size=" +
                ch.size());
        ByteBuffer bb = ch.map(MapMode.READ_ONLY, ch.position(), size);
        bb.order(BYTE_ORDER);

        if (LOG.isDebugEnabled()) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.