All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anaptecs.jeaf.workload.proxy.LowGarbageByteArrayOutputStream Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
/**
 * Copyright 2004 - 2021 anaptecs GmbH, Burgstr. 96, 72764 Reutlingen, Germany
 *
 * All rights reserved.
 */
package com.anaptecs.jeaf.workload.proxy;

import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;

/**
 * Class implements a low garbage variant of a {@link ByteArrayOutputStream}. The only difference to the standard JDK
 * implementation is that the original byte array will be returned in opposite to a copy of it in the original
 * implementation.
 * 
 * @author JEAF Development Team
 */
public class LowGarbageByteArrayOutputStream extends ByteArrayOutputStream {
  /**
   * Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if
   * necessary.
   */
  public LowGarbageByteArrayOutputStream( ) {
    this(0);
  }

  /**
   * Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
   *
   * @param size the initial size.
   * @exception IllegalArgumentException if size is negative.
   */
  public LowGarbageByteArrayOutputStream( int size ) {
    super(size);
  }

  /**
   * Method returns the original byte array where all the data of the stream was written to wrapped by a
   * {@link ByteBuffer}
   * 
   * @return {@link ByteBuffer} ByteBuffer wrapping the internal byte array of the stream. The method never returns
   * null.
   */
  public ByteBuffer getByteBuffer( ) {
    return ByteBuffer.wrap(buf);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy