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 whois(String query, String server) throws IOException {
    Socket sock = new Socket(server, 43);
    int c = 0;//  w  w w.  ja  v  a  2 s.  c  o  m

    OutputStream os = sock.getOutputStream();
    InputStream is = sock.getInputStream();
    query += "\r\n";
    os.write(query.getBytes("iso8859_1"));

    while (c != -1) {
        c = is.read();
        if (c != -1)
            System.out.println((char) c);
    }
}

From source file:Main.java

/**
 * Writes a "short" value to an OutputStream. The value is
 * converted to the opposed endian system while writing.
 * @param output target OutputStream//w  w w  .j ava2 s.c  om
 * @param value value to write
 * @throws IOException in case of an I/O problem
 */
public static void writeSwappedShort(OutputStream output, short value) throws IOException {
    output.write((byte) ((value >> 0) & 0xff));
    output.write((byte) ((value >> 8) & 0xff));
}

From source file:Main.java

/**
 * Writes a "int" value to an OutputStream. The value is
 * converted to the opposed endian system while writing.
 * @param output target OutputStream// ww w  .  j  a  v a 2 s  .  c o m
 * @param value value to write
 * @throws IOException in case of an I/O problem
 */
public static void writeSwappedInteger(OutputStream output, int value) throws IOException {
    output.write((byte) ((value >> 0) & 0xff));
    output.write((byte) ((value >> 8) & 0xff));
    output.write((byte) ((value >> 16) & 0xff));
    output.write((byte) ((value >> 24) & 0xff));
}

From source file:net.darkmist.alib.io.Spew.java

/** @deprecated Use {@link java.io.OutputStream#write(byte[])} instead */
@Deprecated/*from  w w  w  .  j  a  v  a 2 s. c  o  m*/
public static void spew(OutputStream stream, byte[] data) throws IOException {
    stream.write(data);
}

From source file:Main.java

public static void writeFully(File file, byte[] data) throws IOException {
    final OutputStream out = new FileOutputStream(file);
    try {//from   w  ww.j  av a2s.  c  o  m
        out.write(data);
    } finally {
        out.close();
    }
}

From source file:Main.java

public static void connectAndSendHttp(ByteArrayOutputStream baos) {
    try {/*from ww w  . j ava  2  s  .c  om*/

        URL url;
        url = new URL("http://10.0.2.2:8080");

        String charset = "UTF-8";

        HttpURLConnection conn;

        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Accept-Charset", charset);
        conn.setRequestProperty("ENCTYPE", "multipart/form-data");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
        OutputStream output = conn.getOutputStream();
        output.write(baos.toByteArray());
        output.close();
        conn.getInputStream();

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static int sendMessage(String auth_token, String registrationId, String message) throws IOException {

    StringBuilder postDataBuilder = new StringBuilder();
    postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId);
    postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
    postDataBuilder.append("&").append("data.payload").append("=")
            .append(URLEncoder.encode("Lars war hier", UTF8));

    byte[] postData = postDataBuilder.toString().getBytes(UTF8);

    // Hit the dm URL.

    URL url = new URL("https://android.clients.google.com/c2dm/send");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);//ww  w .j  ava  2s.c  om
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
    conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
    conn.setRequestProperty("Authorization", "GoogleLogin auth=" + auth_token);

    OutputStream out = conn.getOutputStream();
    out.write(postData);
    out.close();

    int responseCode = conn.getResponseCode();
    return responseCode;
}

From source file:Main.java

public static void writeDouble(OutputStream out, double d) throws IOException {
    long l = Double.doubleToRawLongBits(d);
    out.write(new byte[] { (byte) ((l >> 56) & 0xff), (byte) ((l >> 48) & 0xff), (byte) ((l >> 40) & 0xff),
            (byte) ((l >> 32) & 0xff), (byte) ((l >> 24) & 0xff), (byte) ((l >> 16) & 0xff),
            (byte) ((l >> 8) & 0xff), (byte) (l & 0xff) });
}

From source file:Main.java

public static void startXmlNode(OutputStream out, String indent, String name) throws IOException {
    print(out, indent);/* ww w .jav  a  2 s .  co m*/
    out.write('<');
    print(out, name);
    out.write('>');
    out.write('\n');
}

From source file:com.github.harmanpa.jrecon.utils.Compression.java

public static byte[] compress(byte[] data) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
    OutputStream os = new BZip2CompressorOutputStream(baos);
    os.write(data);
    os.close();/*from w w w  .  j a v a 2s. c om*/
    return baos.toByteArray();
}