Package java.nio

Examples of java.nio.ByteBuffer.rewind()


    }
    else {
      // Verify file header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      fileChannel.read(buf, 0L);
      buf.rewind();

      if (buf.remaining() < HEADER_LENGTH) {
        throw new IOException("File too short to be a compatible ID file");
      }
View Full Code Here


    if (fileChannel.size() == 0L) {
      // Empty file, write header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      buf.put(MAGIC_NUMBER);
      buf.put(FILE_FORMAT_VERSION);
      buf.rewind();

      fileChannel.write(buf, 0L);

      sync();
    }
View Full Code Here

    }
    else {
      // Verify file header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      fileChannel.read(buf, 0L);
      buf.rewind();

      if (buf.remaining() < HEADER_LENGTH) {
        throw new IOException("File too short to be a compatible data file");
      }
View Full Code Here

    long offset = fileChannel.size();

    ByteBuffer buf = ByteBuffer.allocate(data.length + 4);
    buf.putInt(data.length);
    buf.put(data);
    buf.rewind();

    fileChannel.write(buf, offset);

    return offset;
  }
View Full Code Here

            if ( magicBuf.hasRemaining() ) return null;
            magicBuf.flip();
            // copy the read four byte into a buffer - we will need them again maybe
            preReadData = new byte[4];
            magicBuf.get( preReadData );
            magicBuf.rewind();
            // read the first four bytes as int
            int magicNo = magicBuf.getInt();
            isHttp = (magicNo != EJConstants.EJOE_MAGIC_NUMBER);
        }
View Full Code Here

        }

        // validate the data
        if ( !httpHeaderParser.isValid() )
        {
            headerBuf.rewind();
            throw new ParseException( httpHeaderParser.getClass().getName() + ": Invalid HTTP header detected!!!\n"
                    + IOUtil.decodeToString( headerBuf ), 0 );
        }

        return httpHeaderParser;
View Full Code Here

    int tagSize = computeTagLength(compatibleTag, fields);
   
    ByteBuffer buf = ByteBuffer.allocate( tagSize + padding );
    create(compatibleTag, buf, fields, tagSize, padding);
   
    buf.rewind();
    return buf;
    }
   
  protected List createFields(Tag tag) throws UnsupportedEncodingException {
      List fields = new LinkedList();
View Full Code Here

                    String strValue = null;
                    ByteBuffer buffer = (ByteBuffer) value;
                    int toGet = Math.min(16, buffer.limit());
                    byte[] dst = new byte[toGet];
                    buffer.get(dst);
                    buffer.rewind();
                    strValue = new String(dst, 0, dst.length);
                    if (dst.length < buffer.limit()) {
                        strValue += "... [" + (buffer.limit() - toGet) + " bytes more]";
                    }
                    value = strValue;
View Full Code Here

  }

  private ByteBuffer readData(final long iOffset,final  int iSize) throws IOException {
    ByteBuffer buffer = getBuffer(iSize);
    channel.read(buffer, iOffset);
    buffer.rewind();
    return buffer;
  }

  private void writeData(final ByteBuffer iBuffer, final long iOffset) throws IOException {
    iBuffer.rewind();
View Full Code Here

                ByteBuffer pendingValue = record.getPendingDataBuffer();
                pendingValue.clear();
                PrimitiveJavaTypesUtil.primitiveToByteBuffer(objectToPersist, next, pendingValue);
                pendingValue.flip();
                transactionFile.getChannel().write(pendingValue);
                pendingValue.rewind();
            }else {
                try {
                    Utils.writePrimitive(objectToPersist, next,transactionFile);
                } catch (Exception e) {
                    throw new JodbIOException(e);
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.