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");
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(); }
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(); }
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"); }
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(); }
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); }
/** * 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); }
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(); }
@Override public byte[] toBytes() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(getCommand()); out.write(QUIT); return out.toByteArray(); }
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();
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(); }
public byte[] toBytes() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(getCommand()); out.write(getQueryString().getBytes("UTF-8"));// 链接建立时默认指定编码为UTF-8 return out.toByteArray(); }
/** * 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(); } /**
@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(); }
/** * 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(); } }
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(); }
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(); }
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(); }
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(); }