[英]Java - ByteArrayOutputStream replacement but only for 1 value
Is it possible to somehow truncate this in the second case because I don't need an Array.是否可以在第二种情况下以某种方式截断它,因为我不需要 Array. This is my code:
这是我的代码:
public static byte[] createHandshakeMessage(String host, int port, int protocol) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
handshake.writeByte(0x00); //packet id for handshake
//Fields->
//some code...
return buffer.toByteArray();
}
public static byte createClient(){
ByteArrayOutputStream buffer = new ByteArrayOutputStream();//is there a replacement for this?
DataOutputStream handshake = new DataOutputStream(buffer);
handshake.writeByte(0x00); //packet id for login start
String offlineSession = "Username";
//Fields->
writeString(handshake, offlineSession, StandardCharsets.UTF_8);
return buffer.toByteArray();
}
只需使用简单的OutputStream.write(b)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.