Examples of FastByteBuffer


Examples of jodd.util.buffer.FastByteBuffer

  /**
   * Encrypts complete content, block by block.
   */
  public byte[] encrypt(byte[] content) {
    FastByteBuffer fbb = new FastByteBuffer();

    int length = content.length + 1;
    int blockCount = length / blockSizeInBytes;
    int remaining = length;

    int offset = 0;
    for (int i = 0; i < blockCount; i++) {
      if (remaining == blockSizeInBytes) {
        break;
      }
      byte[] encrypted = encryptBlock(content, offset);

      fbb.append(encrypted);

      offset += blockSizeInBytes;
      remaining -= blockSizeInBytes;
    }

    if (remaining != 0) {
      // process remaining bytes
      byte[] block = new byte[blockSizeInBytes];

      System.arraycopy(content, offset, block, 0, remaining - 1);

      block[remaining - 1] = TERMINATOR;

      byte[] encrypted = encryptBlock(block, 0);

      fbb.append(encrypted);
    }

    return fbb.toArray();
  }
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

  /**
   * Decrypts the whole content, block by block.
   */
  public byte[] decrypt(byte[] encryptedContent) {
    FastByteBuffer fbb = new FastByteBuffer();

    int length = encryptedContent.length;
    int blockCount = length / blockSizeInBytes;

    int offset = 0;
    for (int i = 0; i < blockCount - 1; i++) {
      byte[] decrypted = decryptBlock(encryptedContent, offset);

      fbb.append(decrypted);

      offset += blockSizeInBytes;
    }

    // process last block
    byte[] decrypted = decryptBlock(encryptedContent, offset);

    // find terminator
    int ndx = blockSizeInBytes - 1;

    while (ndx >= 0) {
      if (decrypted[ndx] == TERMINATOR) {
        break;
      }
      ndx--;
    }

    fbb.append(decrypted, 0, ndx);

    return fbb.toArray();
  }
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

  /**
   * Ensures that last buffer exist.
   */
  private void ensureLast() {
    if (last == null) {
      last = new FastByteBuffer();
      list.add(last);
    }
  }
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

   * Writes content to the writer.
   */
  public void writeTo(Writer writer) throws IOException {
    for (Object o : list) {
      if (o instanceof FastByteBuffer) {
        FastByteBuffer fastByteBuffer = (FastByteBuffer) o;

        byte[] array = fastByteBuffer.toArray();

        writer.write(new String(array, StringPool.ISO_8859_1));
      }
      else if (o instanceof Uploadable) {
        Uploadable uploadable = (Uploadable) o;
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

   * Writes content to the output stream.
   */
  public void writeTo(OutputStream out) throws IOException {
    for (Object o : list) {
      if (o instanceof FastByteBuffer) {
        FastByteBuffer fastByteBuffer = (FastByteBuffer) o;

        out.write(fastByteBuffer.toArray());
      }
      else if (o instanceof Uploadable) {
        Uploadable uploadable = (Uploadable) o;

        InputStream inputStream = uploadable.openInputStream();
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

    // loop

    for (Object o : list) {
      if (o instanceof FastByteBuffer) {
        FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
        byte[] bytes = fastByteBuffer.toArray();

        int offset = 0;

        while (offset < bytes.length) {
          // calc the remaining sending chunk size
View Full Code Here

Examples of jodd.util.buffer.FastByteBuffer

   *
   * @param size the initial size.
   * @throws IllegalArgumentException if size is negative.
   */
  public FastByteArrayOutputStream(int size) {
    buffer = new FastByteBuffer(size);
  }
View Full Code Here

Examples of org.exist.util.FastByteBuffer

   
    private static final Logger LOG = Logger.getLogger(VariableByteArrayInput.class);
   
    public VariableByteOutputStream() {
        super();
        buf = new FastByteBuffer(9);
    }
View Full Code Here

Examples of org.exist.util.FastByteBuffer

        buf = new FastByteBuffer(9);
    }

    public VariableByteOutputStream(int size) {
        super();
        buf = new FastByteBuffer(size);
    }
View Full Code Here

Examples of org.exist.util.FastByteBuffer

        buf = new FastByteBuffer(size);
    }

    public void clear() {
        if (buf.size() > MAX_BUFFER_SIZE)
            {buf = new FastByteBuffer(9);}
        else
            {buf.setLength(0);}
    }
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.