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 final void writeLine(OutputStream out, String s) throws IOException {
    writeFix(out, s);//ww w  .j  ava2  s.c  o m
    out.write('\r');
    out.write('\n');
}

From source file:invio.util.ArquivoUtil.java

public static void exportaPDF(String path) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    response.setContentType("application/pdf");
    try {/*from  w  w  w  .  j  a v a 2 s.co  m*/
        FileInputStream input = new FileInputStream(path);
        byte[] bytes = IOUtils.toByteArray(input);
        OutputStream output = response.getOutputStream();
        output.write(bytes);
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
    } catch (IOException e) {
    }
}

From source file:Main.java

public static void write(InputStream in, OutputStream out) throws Throwable {
    int read = 0;
    while ((read = in.read()) != -1) {
        out.write(read);
    }/*from   ww  w  . j a v  a 2 s .  co m*/
    in.close();
    out.close();
    out.flush();
}

From source file:Main.java

public static void writeLine(OutputStream os, PrintWriter logWriter, String value) throws IOException {
    String line = value + "\n";
    os.write(line.getBytes());
    if (logWriter != null) {
        logWriter.println(value);// w w  w  .  j  a v a  2  s  . c  o  m
    }
}

From source file:OutputStreamDemo.java

static void writeints(String msg, int count, OutputStream os) throws IOException {
    long currentTime = System.currentTimeMillis();
    for (int i = 0; i < count; i++)
        os.write(i & 255);
    os.close();//from w  ww. j  a v  a  2s.c  o m
    System.out.println(msg + Long.toString(System.currentTimeMillis() - currentTime));
}

From source file:Main.java

public static void write(InputStream in, OutputStream out) throws IOException {
    int read = 0;
    while ((read = in.read()) != -1) {
        out.write(read);
    }//ww  w  .j av  a  2  s  . com
    in.close();
    out.close();
    out.flush();
}

From source file:Main.java

public static void saveByteData(byte[] bytes, File pictureFile) throws IOException {
    OutputStream output = null;
    try {//  w  ww  .ja v  a  2s .  c  o  m
        output = new FileOutputStream(pictureFile);
        output.write(bytes);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (output != null) {
            output.close();
        }
    }
}

From source file:Main.java

public static void savePicture(byte[] picture) throws IOException {

    OutputStream out = null;
    try {// w  w  w  . ja  v  a  2  s . c om
        out = new FileOutputStream(PICTURE_TEMP_PATH);
        out.write(picture);
        out.flush();

    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:Main.java

public static String tests(String cmd) {
    OutputStream out = process.getOutputStream();

    try {/* w  w  w . jav  a 2  s  . c o m*/

        out.write(cmd.getBytes());
        out.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static String getToken(String email, String password) throws IOException {
    // Create the post data
    // Requires a field with the email and the password
    StringBuilder builder = new StringBuilder();
    builder.append("Email=").append(email);
    builder.append("&Passwd=").append(password);
    builder.append("&accountType=GOOGLE");
    builder.append("&source=markson.visuals.sitapp");
    builder.append("&service=ac2dm");

    // Setup the Http Post
    byte[] data = builder.toString().getBytes();
    URL url = new URL("https://www.google.com/accounts/ClientLogin");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setUseCaches(false);/*from   w  w  w  .  j  a  v  a 2  s.co  m*/
    con.setDoOutput(true);
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    con.setRequestProperty("Content-Length", Integer.toString(data.length));

    // Issue the HTTP POST request
    OutputStream output = con.getOutputStream();
    output.write(data);
    output.close();

    // Read the response
    BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line = null;
    String auth_key = null;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("Auth=")) {
            auth_key = line.substring(5);
        }
    }

    // Finally get the authentication token
    // To something useful with it
    return auth_key;
}