org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer()方法的一些代码示例,展示了ByteArrayOutputStream.needNewBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.needNewBuffer()方法的具体详情如下:
包路径:org.apache.commons.io.output.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:needNewBuffer

ByteArrayOutputStream.needNewBuffer介绍

[英]Makes a new buffer available either by allocating a new one or re-cycling an existing one.
[中]通过分配新缓冲区或重新循环现有缓冲区,使新缓冲区可用。

代码示例

代码示例来源:origin: commons-io/commons-io

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
@Override
public synchronized void write(final int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Creates a new byte array output stream, with a buffer capacity of
 * the specified size, in bytes.
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(final int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  synchronized (this) {
    needNewBuffer(size);
  }
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * @see java.io.OutputStream#write(int)
 */
public synchronized void write(int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Writes the entire contents of the specified input stream to this
 * byte stream. Bytes from the input stream are read directly into the
 * internal buffers of this streams.
 *
 * @param in the input stream to read from
 * @return total number of bytes read from the input stream
 *         (and written to this stream)
 * @throws IOException if an I/O error occurs while reading the input stream
 * @since 1.4
 */
public synchronized int write(final InputStream in) throws IOException {
  int readCount = 0;
  int inBufferPos = count - filledBufferSum;
  int n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
  while (n != EOF) {
    readCount += n;
    inBufferPos += n;
    count += n;
    if (inBufferPos == currentBuffer.length) {
      needNewBuffer(currentBuffer.length);
      inBufferPos = 0;
    }
    n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
  }
  return readCount;
}

代码示例来源:origin: commons-io/commons-io

/**
 * @see java.io.ByteArrayOutputStream#reset()
 */
public synchronized void reset() {
  count = 0;
  filledBufferSum = 0;
  currentBufferIndex = 0;
  if (reuseBuffers) {
    currentBuffer = buffers.get(currentBufferIndex);
  } else {
    //Throw away old buffers
    currentBuffer = null;
    final int size = buffers.get(0).length;
    buffers.clear();
    needNewBuffer(size);
    reuseBuffers = true;
  }
}

代码示例来源:origin: org.apache.commons/commons-io

/**
 * Creates a new byte array output stream, with a buffer capacity of 
 * the specified size, in bytes. 
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  needNewBuffer(size);
}

代码示例来源:origin: commons-io/commons-io

remaining -= part;
if (remaining > 0) {
  needNewBuffer(newcount);
  inBufferPos = 0;

代码示例来源:origin: org.apache.commons/commons-io

/**
 * @see java.io.OutputStream#write(byte[], int, int)
 */
public void write(byte[] b, int off, int len) {
  if ((off < 0) 
      || (off > b.length) 
      || (len < 0) 
      || ((off + len) > b.length) 
      || ((off + len) < 0)) {
    throw new IndexOutOfBoundsException();
  } else if (len == 0) {
    return;
  }
  synchronized (this) {
    int newcount = count + len;
    int remaining = len;
    int inBufferPos = count - filledBufferSum;
    while (remaining > 0) {
      int part = Math.min(remaining, currentBuffer.length - inBufferPos);
      System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part);
      remaining -= part;
      if (remaining > 0) {
        needNewBuffer(newcount);
        inBufferPos = 0;
      }
    }
    count = newcount;
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
@Override
public synchronized void write(final int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
public synchronized void write(int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: org.onosproject/onlab-thirdparty

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
@Override
public synchronized void write(int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-io

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
public synchronized void write(int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
@Override
public synchronized void write(final int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: Nextdoor/bender

/**
 * Write a byte to byte array.
 * @param b the byte to write
 */
@Override
public synchronized void write(int b) {
  int inBufferPos = count - filledBufferSum;
  if (inBufferPos == currentBuffer.length) {
    needNewBuffer(count + 1);
    inBufferPos = 0;
  }
  currentBuffer[inBufferPos] = (byte) b;
  count++;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-io

/**
 * Creates a new byte array output stream, with a buffer capacity of 
 * the specified size, in bytes. 
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  needNewBuffer(size);
}

代码示例来源:origin: Nextdoor/bender

/**
 * Creates a new byte array output stream, with a buffer capacity of 
 * the specified size, in bytes. 
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  synchronized (this) {
    needNewBuffer(size);
  }
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io

/**
 * Creates a new byte array output stream, with a buffer capacity of 
 * the specified size, in bytes. 
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  needNewBuffer(size);
}

代码示例来源:origin: org.onosproject/onlab-thirdparty

/**
 * Creates a new byte array output stream, with a buffer capacity of 
 * the specified size, in bytes. 
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  synchronized (this) {
    needNewBuffer(size);
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Creates a new byte array output stream, with a buffer capacity of
 * the specified size, in bytes.
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(final int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  synchronized (this) {
    needNewBuffer(size);
  }
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Creates a new byte array output stream, with a buffer capacity of
 * the specified size, in bytes.
 *
 * @param size  the initial size
 * @throws IllegalArgumentException if size is negative
 */
public ByteArrayOutputStream(final int size) {
  if (size < 0) {
    throw new IllegalArgumentException(
      "Negative initial size: " + size);
  }
  synchronized (this) {
    needNewBuffer(size);
  }
}

相关文章