Java Utililty Methods OutputStream Write

List of utility methods to do OutputStream Write

Description

The list of methods to do OutputStream Write are organized into topic(s).

Method

voidserializeUUID(OutputStream out, UUID id)
serialize UUID
long msb = id.getMostSignificantBits();
long lsb = id.getLeastSignificantBits();
byte[] data = new byte[16];
data[0] = (byte) ((msb >>> 56));
data[1] = (byte) ((msb >>> 48));
data[2] = (byte) ((msb >>> 40));
data[3] = (byte) ((msb >>> 32));
data[4] = (byte) ((msb >>> 24));
...
voidwriteStream(byte[] data, OutputStream os)
write Stream
os.write(data);
os.flush();
voidwriteStream(byte[] data, OutputStream out)
Writes data into the stream and closes the output stream
try {
    out.write(data);
    out.flush();
} finally {
    out.close();
voidwriteStream(final OutputStream out, final String content, final boolean close)
Write a string
final PrintWriter writer = new PrintWriter(out);
writer.println(content);
if (close) {
    writer.close();
voidwriteStream(InputStream _from, Writer _printTo)
write Stream
final Reader in = new BufferedReader(new InputStreamReader(new BufferedInputStream(_from)));
while (in.ready())
    _printTo.write(in.read());
voidwriteStream(InputStream in, File file)
Writes all data that can be read from the supplied InputStream to the specified file.
FileOutputStream out = new FileOutputStream(file);
try {
    transfer(in, out);
} finally {
    try {
        out.flush();
    } finally {
        out.close();
...
voidwriteStream(InputStream inputStream, OutputStream out)
write Stream
try {
    int read = 0;
    byte[] bytes = new byte[inputStream.available()];
    while ((read = inputStream.read(bytes)) > 0) {
        out.write(bytes, 0, read);
    inputStream.close();
    out.flush();
...
voidwriteStream(OutputStream out, byte[] data)
write Stream
voidwriteStream(OutputStream output, String dataStr)
Writes a String to the specified OutputStream
byte data[] = dataStr.getBytes();
output.write(data, 0, data.length);
intwriteStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)
write Stream
int totalWritten = 0;
int read = 0;
while ((read = inputStream.read(buffer)) > 0) {
    outputStream.write(buffer, 0, read);
    totalWritten += read;
return totalWritten;