Example usage for java.io OutputStream write

List of usage examples for java.io OutputStream write

Introduction

In this page you can find the example usage for java.io OutputStream write.

Prototype

public void write(byte b[]) throws IOException 

Source Link

Document

Writes b.length bytes from the specified byte array to this output stream.

Usage

From source file:Main.java

public static void writeStringToFile(String text, String file) throws IOException {
    OutputStream os = new FileOutputStream(file);
    os.write(text.getBytes());
    os.close();//from   w w  w .  j av  a  2  s  .  c om
}

From source file:edu.rit.flick.genetics.util.HexPrinter.java

public static void shortToFile(final short s, final OutputStream out) throws IOException {
    out.write(new byte[] { (byte) (s >> 8), (byte) (s & 0b1111_1111) });
}

From source file:Main.java

public static void writeFanout(List<String> childCrcs, long actualContentLength, OutputStream bout)
        throws IOException {
    bout.write((actualContentLength + "").getBytes());
    for (String l : childCrcs) {
        bout.write("\n".getBytes());
        bout.write(l.getBytes());/*w w  w.  j a  va  2 s.co m*/
    }
    bout.flush();
}

From source file:Main.java

public static void writeInt(OutputStream os, int n) throws IOException {
    os.write((n >> 0) & 0xff);
    os.write((n >> 8) & 0xff);
    os.write((n >> 16) & 0xff);
    os.write((n >> 24) & 0xff);
}

From source file:Main.java

/**
 * Write long./*from   w  w  w. ja  v  a 2 s  . co m*/
 *
 * @param os the os
 * @param n the n
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void writeLong(OutputStream os, long n) throws IOException {
    os.write((byte) (n >>> 0));
    os.write((byte) (n >>> 8));
    os.write((byte) (n >>> 16));
    os.write((byte) (n >>> 24));
    os.write((byte) (n >>> 32));
    os.write((byte) (n >>> 40));
    os.write((byte) (n >>> 48));
    os.write((byte) (n >>> 56));
}

From source file:Main.java

public static void spitFile(String outputfile, byte[] b) throws IOException {
    OutputStream os = context.openFileOutput(outputfile, Context.MODE_PRIVATE);
    os.write(b);
    os.close();//from  www.j  av  a2  s . co  m
}

From source file:BufferDiff.java

static int time(OutputStream os) throws IOException {
    Date then = new Date();
    for (int i = 0; i < 500000; i++) {
        os.write(1);
    }/*  ww w. jav a 2s  .co m*/
    os.close();
    return (int) ((new Date()).getTime() - then.getTime());
}

From source file:Main.java

public static void writeTextToUri(Context context, Uri uri, String string) throws IOException {
    OutputStream outputStream = context.getContentResolver().openOutputStream(uri);
    outputStream.write(string.getBytes());
    outputStream.close();/*from w  ww  . j a v  a  2  s.c o m*/
}

From source file:Main.java

private static void writeJavaIntAsDelphiLongInt(OutputStream os, int intValue) throws IOException {
    os.write(intValue);
    intValue >>= 8;/*from w  w w  .  j  av  a 2 s. c  om*/
    os.write(intValue);
    intValue >>= 8;
    os.write(intValue);
    intValue >>= 8;
    os.write(intValue);
    intValue >>= 8;
}

From source file:Main.java

public static void writeFile(File file, byte[] data) throws IOException {
    OutputStream out = new FileOutputStream(file);
    try {/*  w w  w .  j  a  v a 2s . c om*/
        out.write(data);
        out.flush();
        out.close();
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            // Do nothing.
        }
    }
}