java.io.ByteArrayOutputStream.write()方法的使用及代码示例

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

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

ByteArrayOutputStream.write介绍

[英]Writes the specified byte oneByte to the OutputStream. Only the low order byte of oneByte is written.
[中]将指定的字节一个字节写入OutputStream。只写入一个字节的低位字节。

代码示例

代码示例来源:origin: stackoverflow.com

ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
  result.write(buffer, 0, length);
}
return result.toString("UTF-8");

代码示例来源:origin: bumptech/glide

public static byte[] isToBytes(InputStream is) throws IOException {
 ByteArrayOutputStream os = new ByteArrayOutputStream();
 byte[] buffer = new byte[1024];
 int read;
 try {
  while ((read = is.read(buffer)) != -1) {
   os.write(buffer, 0, read);
  }
 } finally {
  is.close();
 }
 return os.toByteArray();
}

代码示例来源:origin: jenkinsci/jenkins

public void run() {
    int b;
    try {
      // not all InputStream will look for the thread interrupt flag, so check that explicitly to be defensive
      while (!Thread.interrupted() && (b=source.read())!=-1) {
        readAhead.write(b);
      }
    } catch (IOException e) {
      error[0] = e;
    }
  }
};

代码示例来源:origin: alibaba/canal

public static byte[] readNullTerminatedBytes(byte[] data, int index) {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  for (int i = index; i < data.length; i++) {
    byte item = data[i];
    if (item == MSC.NULL_TERMINATED_STRING_DELIMITER) {
      break;
    }
    out.write(item);
  }
  return out.toByteArray();
}

代码示例来源:origin: alibaba/arthas

public static String toString(InputStream inputStream) throws IOException {
  ByteArrayOutputStream result = new ByteArrayOutputStream();
  byte[] buffer = new byte[1024];
  int length;
  while ((length = inputStream.read(buffer)) != -1) {
    result.write(buffer, 0, length);
  }
  return result.toString("UTF-8");
}

代码示例来源:origin: libgdx/libgdx

private static byte[] readAllBytes(InputStream input) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int numRead;
  byte[] buffer = new byte[16384];
  while ((numRead = input.read(buffer, 0, buffer.length)) != -1) {
    out.write(buffer, 0, numRead);
  }
  return out.toByteArray();
}

代码示例来源:origin: spring-projects/spring-framework

private String readCommand(ByteBuffer byteBuffer) {
  ByteArrayOutputStream command = new ByteArrayOutputStream(256);
  while (byteBuffer.remaining() > 0 && !tryConsumeEndOfLine(byteBuffer)) {
    command.write(byteBuffer.get());
  }
  return new String(command.toByteArray(), StandardCharsets.UTF_8);
}

代码示例来源:origin: redisson/redisson

/**
 * Constructs a writer.
 * @param size      the initial buffer size.
 */
public Writer(int size) {
  output = new ByteArrayOutputStream(size);
  numOfEntries = 0;
  output.write(0);        // u2 number_of_entries
  output.write(0);
}

代码示例来源:origin: libgdx/libgdx

private static byte[] readAllBytes(InputStream input) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int numRead;
  byte[] buffer = new byte[16384];
  while ((numRead = input.read(buffer, 0, buffer.length)) != -1) {
    out.write(buffer, 0, numRead);
  }
  return out.toByteArray();
}

代码示例来源:origin: alibaba/canal

@Override
public byte[] toBytes() throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  out.write(getCommand());
  out.write(QUIT);
  return out.toByteArray();
}

代码示例来源:origin: stackoverflow.com

BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
  buf.write((byte) result);
  result = bis.read();
}
return buf.toString();

代码示例来源:origin: Tencent/tinker

public static byte[] readStream(InputStream is, int initSize) throws IOException {
  if (initSize <= 0) {
    initSize = 32 * 1024;
  }
  ByteArrayOutputStream baos = new ByteArrayOutputStream(initSize);
  byte[] buffer = new byte[8192];
  int bytesRead;
  while ((bytesRead = is.read(buffer)) > 0) {
    baos.write(buffer, 0, bytesRead);
  }
  return baos.toByteArray();
}

代码示例来源:origin: alibaba/canal

public byte[] toBytes() throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  out.write(getCommand());
  out.write(getQueryString().getBytes("UTF-8"));// 链接建立时默认指定编码为UTF-8
  return out.toByteArray();
}

代码示例来源:origin: Tencent/tinker

/**
 * Returns a byte[] containing the remainder of 'in'.
 */
public static byte[] readFullyNoClose(InputStream in) throws IOException {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  byte[] buffer = new byte[1024];
  int count;
  while ((count = in.read(buffer)) != -1) {
    bytes.write(buffer, 0, count);
  }
  return bytes.toByteArray();
}
/**

代码示例来源:origin: alibaba/canal

@Override
public byte[] encode() throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ByteHelper.writeUnsignedInt64LittleEndian(sets.size(), out);
  for (Map.Entry<String, UUIDSet> entry : sets.entrySet()) {
    out.write(entry.getValue().encode());
  }
  return out.toByteArray();
}

代码示例来源:origin: Tencent/tinker

/**
   * input stream to byte
   * @param in InputStream
   * @return byte[]
   * @throws IOException
   */
  public static byte[] inputStreamToByte(InputStream in) throws IOException {

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    byte[] data = new byte[BUFFER_SIZE];
    int count = -1;
    while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
      outStream.write(data, 0, count);
    }

    data = null;
    return outStream.toByteArray();
  }
}

代码示例来源:origin: alibaba/canal

public byte[] encode() throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
  bb.putLong(SID.getMostSignificantBits());
  bb.putLong(SID.getLeastSignificantBits());
  out.write(bb.array());
  ByteHelper.writeUnsignedInt64LittleEndian(intervals.size(), out);
  for (Interval interval : intervals) {
    ByteHelper.writeUnsignedInt64LittleEndian(interval.start, out);
    ByteHelper.writeUnsignedInt64LittleEndian(interval.stop, out);
  }
  return out.toByteArray();
}

代码示例来源:origin: pxb1988/dex2jar

private static byte[] toByteArray(InputStream is) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  byte[] buff = new byte[1024];
  for (int c = is.read(buff); c > 0; c = is.read(buff)) {
    out.write(buff, 0, c);
  }
  return out.toByteArray();
}

代码示例来源:origin: alibaba/canal

public byte[] toBytes() throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream(5);
  out.write(this.fieldCount);
  ByteHelper.writeUnsignedShortLittleEndian(this.warningCount, out);
  ByteHelper.writeUnsignedShortLittleEndian(this.statusFlag, out);
  return out.toByteArray();
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

private byte[] readBytes(InputStream inputStream) throws IOException {
  ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
  int bufferSize = 1024;
  byte[] buffer = new byte[bufferSize];
  int len = 0;
  while ((len = inputStream.read(buffer)) != -1) {
    byteBuffer.write(buffer, 0, len);
  }
  return byteBuffer.toByteArray();
}

相关文章