Example usage for java.io DataOutputStream DataOutputStream

List of usage examples for java.io DataOutputStream DataOutputStream

Introduction

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

Prototype

public DataOutputStream(OutputStream out) 

Source Link

Document

Creates a new data output stream to write data to the specified underlying output stream.

Usage

From source file:com.maverick.ssl.SSLTransportImpl.java

public void initialize(InputStream in, OutputStream out, SSLContext context) throws IOException, SSLException {

    this.rawIn = new DataInputStream(in);
    this.rawOut = new DataOutputStream(out);
    writeCipherSuite = readCipherSuite = new SSL_NULL_WITH_NULL_NULL();

    // #ifdef DEBUG
    log.debug(Messages.getString("SSLTransport.initialising")); //$NON-NLS-1$
    // #endif/*from   w w w.  jav a2 s. c  om*/

    if (context == null)
        context = new SSLContext();

    handshake = new SSLHandshakeProtocol(this, context);

    // Start the handshake
    handshake.startHandshake();

    // While the handshake is not complete process all the messages
    while (!handshake.isComplete()) {
        processMessages();

        // #ifdef DEBUG
        log.debug(Messages.getString("SSLTransport.initCompleteStartingAppProtocol")); //$NON-NLS-1$
        // #endif
    }
}

From source file:com.github.terma.m.server.Repo.java

public void storeMetricCodes(final Map<String, Short> metricCodes) throws IOException {
    DataOutputStream dos = null;//from   w  ww .ja  va2s . c o  m
    try {
        dos = new DataOutputStream(new FileOutputStream(eventCodesFile));
        for (Map.Entry<String, Short> metricCode : metricCodes.entrySet()) {
            dos.writeUTF(metricCode.getKey());
            dos.writeShort(metricCode.getValue());
        }
    } finally {
        IOUtils.closeQuietly(dos);
    }
}

From source file:ro.bmocanu.trafficproxy.peers.PeerCommunicationServer.java

/**
 * {@inheritDoc}//from   w w w .  j  av a2s. c om
 */
@Override
protected void internalRun() throws Exception {
    if (!clientSocket.isClosed() && peerChannel.isConnectionUp()) {
        // nothing to do if the connection is still on
        return;
    }

    try {
        LOG.info("Waiting for incoming peer connections");
        clientSocket = serverSocket.accept();

        LOG.info("Peer connection established");
        peerChannel.setInputStream(new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())));
        peerChannel.setOutputStream(
                new DataOutputStream(new BufferedOutputStream(clientSocket.getOutputStream())));
        peerChannel.setConnectionUp(true);

    } catch (SocketTimeoutException exception) {
        // this is ok, it is expected
    }
}

From source file:de.hybris.platform.cuppytrail.impl.DefaultSecureTokenService.java

@Override
public String encryptData(final SecureToken data) {
    if (data == null || StringUtils.isBlank(data.getData())) {
        throw new IllegalArgumentException("missing token");
    }/*w w  w. ja v  a 2s  . c om*/
    try {
        final SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
        final int[] paddingSizes = computePaddingLengths(random);

        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
        dataOutputStream.write(generatePadding(paddingSizes[0], random));
        dataOutputStream.writeUTF(data.getData());
        dataOutputStream.writeUTF(createChecksum(data.getData()));
        dataOutputStream.writeLong(data.getTimeStamp());
        dataOutputStream.write(generatePadding(paddingSizes[1], random));

        dataOutputStream.flush();
        final byte[] unsignedDataBytes = byteArrayOutputStream.toByteArray();

        final byte[] md5SigBytes = generateSignature(unsignedDataBytes, 0, unsignedDataBytes.length,
                signatureKeyBytes);
        byteArrayOutputStream.write(md5SigBytes);
        byteArrayOutputStream.flush();

        final byte[] signedDataBytes = byteArrayOutputStream.toByteArray();

        return encrypt(signedDataBytes, encryptionKeyBytes, random);
    } catch (final IOException e) {
        LOG.error("Could not encrypt", e);
        throw new SystemException(e.toString(), e);
    } catch (final GeneralSecurityException e) {
        LOG.error("Could not encrypt", e);
        throw new SystemException(e.toString(), e);
    }
}

From source file:mitm.common.security.password.PBEncryptionParameters.java

/**
 * Returns the encoded form of PBEncryptionParameters.
 *//*w  w  w  . jav a2 s .  co m*/
public byte[] getEncoded() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    DataOutputStream out = new DataOutputStream(bos);

    out.writeLong(serialVersionUID);

    out.writeInt(salt.length);
    out.write(salt);

    out.writeInt(iterationCount);

    out.writeInt(encryptedData.length);
    out.write(encryptedData);

    return bos.toByteArray();
}

From source file:de.ingrid.communication.authentication.BasicSchemeConnector.java

private DataOutputStream createOutput(Socket socket) throws IOException {
    OutputStream outputStream = socket.getOutputStream();
    DataOutputStream dataOutput = new DataOutputStream(new BufferedOutputStream(outputStream, 65535));
    return dataOutput;
}

From source file:com.example.scandevice.MainActivity.java

public static String excutePost(String targetURL, String urlParameters) {
    URL url;/*  w w  w . j  a  v  a2  s .  c o  m*/
    HttpURLConnection connection = null;
    try {
        //Create connection
        url = new URL(targetURL);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Accept", "application/json");
        connection.setRequestProperty("charset", "utf-8");

        connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
        connection.setRequestProperty("Content-Language", "en-US");

        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);

        //Send request
        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();

    } catch (Exception e) {
        e.printStackTrace();
        return "Don't post data";

    } finally {

        if (connection != null) {
            connection.disconnect();
        }
    }
    return "Data Sent";
}

From source file:com.pinterest.deployservice.chat.HipChatManager.java

@Override
public void send(String from, String room, String message, String color) throws Exception {
    HashMap<String, String> params = new HashMap<>();
    params.put(ROOM_ID_KEY, URLEncoder.encode(room, "UTF-8"));
    params.put(USER_KEY, URLEncoder.encode(from, "UTF-8"));
    params.put(MESSAGE_KEY, URLEncoder.encode(message, "UTF-8"));
    if (color != null) {
        params.put(COLOR_KEY, color);/*from www  . ja  v a 2  s. c  o  m*/
    }

    final String paramsToSend = this.constructQuery(params);
    String url = requestURL;
    DataOutputStream output = null;
    HttpURLConnection connection = null;
    for (int i = 0; i < TOTAL_RETRY; i++) {
        try {
            URL requestUrl = new URL(url);
            connection = (HttpURLConnection) requestUrl.openConnection();
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("Content-Length", Integer.toString(paramsToSend.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");
            output = new DataOutputStream(connection.getOutputStream());
            output.writeBytes(paramsToSend);
            return;
        } catch (Exception e) {
            LOG.error("Failed to send Hipchat message to room " + room, e);
        } finally {
            IOUtils.closeQuietly(output);
            if (connection != null) {
                connection.disconnect();
            }
        }
        Thread.sleep(1000);
    }
    LOG.error("Failed to send Hipchat message to room " + room);
}

From source file:by.logscanner.LogScanner.java

private void read(File file) throws FileNotFoundException, IOException {
    DataOutputStream out = new DataOutputStream(baos);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

    Stream<String> lines = Files.lines(file.toPath(), StandardCharsets.UTF_8);
    for (String temp : (Iterable<String>) lines::iterator) {
        out.writeUTF((temp.contains(sdf.format(date)) && temp.contains("[" + startupId + "." + requestNo + "]"))
                ? temp + "\n"
                : "");
    }//  www . jav  a  2  s  .c  o m
}

From source file:com.esri.geoevent.test.tools.GetMapServiceCountRunnable.java

private int getMsLayerCount(String url) {
    int cnt = -1;

    try {//from  www.ja  v  a  2  s.  c om
        URL obj = new URL(url + "/query");
        HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

        //add reuqest header
        con.setRequestMethod("POST");

        con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
        con.setRequestProperty("Accept", "text/plain");

        String urlParameters = "where=" + URLEncoder.encode("1=1", "UTF-8") + "&returnCountOnly="
                + URLEncoder.encode("true", "UTF-8") + "&f=" + URLEncoder.encode("json", "UTF-8");

        // Send post request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuilder response = new StringBuilder();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        //print result
        String jsonString = response.toString();

        JSONTokener tokener = new JSONTokener(jsonString);

        JSONObject root = new JSONObject(tokener);

        cnt = root.getInt("count");

    } catch (Exception e) {
        cnt = -2;
    } finally {
        return cnt;
    }

}