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

voidwriteStream(String content, String charset, OutputStream outputStream)
write Stream
if (content != null) {
    outputStream.write(content.getBytes(charset));
    outputStream.flush();
intwriteStreamBuffered(final Reader in, final Writer out)
write Stream Buffered
return writeStreamBuffered(in, out, DEFAULT_BUFFER_SIZE);
voidwriteStreamCharwise(final Reader in, final Writer out)
write Stream Charwise
for (int read; (read = in.read()) != -1;) {
    out.write(read);
intwriteStreamCharwiseLimited(final Reader in, final Writer out, final int len)
write Stream Charwise Limited
int read;
int count = 0;
while (true) {
    read = in.read();
    if (read == -1) {
        return count;
    out.write(read);
...
voidwriteStreamFromString(String contents, OutputStream outputStream)
write Stream From String
if (contents == null) {
    return;
char[] buffer = new char[0x10000];
Reader in = new InputStreamReader(new ByteArrayInputStream(contents.getBytes("UTF-8"))); 
Writer out = new OutputStreamWriter(outputStream, "UTF-8"); 
int read;
do {
...
ObjectOutputStreamwriteStreamFromString(String serializePath)
write Stream From String
ObjectOutputStream oos;
if (serializePath.endsWith(".gz")) {
    oos = new ObjectOutputStream(
            new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(serializePath))));
} else {
    oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(serializePath)));
return oos;
...
voidwriteStreamInFile(File f, InputStream in)
write Stream In File
FileOutputStream fout = null;
byte[] buffer = new byte[4096]; 
int bytesRead;
fout = new FileOutputStream(f);
while ((bytesRead = in.read(buffer)) >= 0) {
    fout.write(buffer, 0, bytesRead);
in.close();
...
voidwriteStreamText(OutputStream out, String text)
Writes the text data to the specified output stream.
writeLinesCommon(out, text);
byte[]writeStreamToArray(InputStream stream)
write Stream To Array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length = 0;
while ((length = stream.read(buffer)) != -1)
    baos.write(buffer, 0, length);
return baos.toByteArray();
voidwriteStreamToStream(InputStream in, OutputStream out)
write Stream To Stream
byte[] buff = new byte[1024];
for (int read = in.read(buff); read > 0; read = in.read(buff)) {
    out.write(buff, 0, read);