Example usage for java.io DataInputStream DataInputStream

List of usage examples for java.io DataInputStream DataInputStream

Introduction

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

Prototype

public DataInputStream(InputStream in) 

Source Link

Document

Creates a DataInputStream that uses the specified underlying InputStream.

Usage

From source file:net.mohatu.bloocoin.miner.RegCustom.java

private void register() {
    try {//  ww  w . ja  va2  s  .  com
        String result = new String();
        Socket sock = new Socket(this.url, this.port);
        String command = "{\"cmd\":\"register" + "\",\"addr\":\"" + addr + "\",\"pwd\":\"" + key + "\"}";
        DataInputStream is = new DataInputStream(sock.getInputStream());
        DataOutputStream os = new DataOutputStream(sock.getOutputStream());
        os.write(command.getBytes());
        os.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            result += inputLine;
        }

        is.close();
        os.close();
        sock.close();
        System.out.println(result);
        if (result.contains("\"success\": true")) {
            System.out.println("Registration successful: " + addr);
            saveBloostamp();
        } else if (result.contains("\"success\": false")) {
            System.out.println("Result: Failed");
            JOptionPane.showMessageDialog(Main.scrollPane,
                    "Registration failed.\nCheck your network connection", "Registration Failed",
                    JOptionPane.ERROR_MESSAGE);
            System.exit(0);
        }
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.mohatu.bloocoin.miner.RegisterClass.java

private void register() {
    try {// w  ww.  j  av a  2 s.  co  m
        String result = new String();
        Socket sock = new Socket(this.url, this.port);
        String command = "{\"cmd\":\"register" + "\",\"addr\":\"" + addr + "\",\"pwd\":\"" + key + "\"}";
        DataInputStream is = new DataInputStream(sock.getInputStream());
        DataOutputStream os = new DataOutputStream(sock.getOutputStream());
        os.write(command.getBytes());
        os.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            result += inputLine;
        }

        is.close();
        os.close();
        sock.close();
        System.out.println(result);
        if (result.contains("\"success\": true")) {
            System.out.println("Registration successful: " + addr);
            saveBloostamp();
        } else if (result.contains("\"success\": false")) {
            System.out.println("Result: Failed");
            MainView.updateStatusText("Registration failed. ");
            System.exit(0);
        }
    } catch (UnknownHostException e) {
        System.out.println("Error: Unknown host.");
    } catch (IOException e) {
        System.out.println("Error: Network error.");
    }
}

From source file:de.dentrassi.rpm.RpmInputStream.java

public RpmInputStream(final InputStream in) {
    this.count = new CountingInputStream(in);
    this.in = new DataInputStream(this.count);
}

From source file:eu.stratosphere.pact.runtime.task.util.SerializationCopier.java

/**
 * Creates a SerializationCopier with an byte array of initial size 1024 byte.
 *//*from  www  .j  av  a 2  s  .  c  om*/
public SerializationCopier() {
    serializedCopy = new byte[1024];
    baos = new ByteArrayOutputStream();
    dos = new DataOutputStream(baos);
    bais = new ByteArrayInputStream(serializedCopy);
    dis = new DataInputStream(bais);
}

From source file:tachyon.master.Image.java

/**
 * Load an image into the masterinfo.//from www . j  a  va2 s. c  o  m
 * 
 * @param info the masterinfo to fill.
 * @param path the data to load
 * @throws IOException
 */
public static void load(MasterInfo info, String path) throws IOException {
    UnderFileSystem ufs = UnderFileSystem.get(path, info.getTachyonConf());
    if (!ufs.exists(path)) {
        LOG.info("Image " + path + " does not exist.");
        return;
    }
    LOG.info("Loading image " + path);
    DataInputStream imageIs = new DataInputStream(ufs.open(path));
    JsonParser parser = JsonObject.createObjectMapper().getFactory().createParser(imageIs);

    info.loadImage(parser, new TachyonURI(path));
    imageIs.close();
    ufs.close();
}

From source file:org.openxdata.server.service.impl.FormDownloadServiceTest.java

@Test
@Ignore("throws too many exceptions")
public void testSubmitForms_noSerializer() throws Exception {

    // create the stream
    final PipedOutputStream pout = new PipedOutputStream();
    DataInputStream in = new DataInputStream(new PipedInputStream(pout));
    Thread thread = new Thread(new Runnable() {
        @Override//from   w w  w .  j a  v a  2  s.com
        public void run() {
            DataOutput output = new DataOutputStream(pout);
            try {
                output.writeByte(1);
                output.writeUTF(XFormsFixture.getSampleFormModelData());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    thread.start();
    DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream());

    // run test
    formDownloadService.submitForms(in, out, null);

    // do checks afterwards
    List<FormDataHeader> formData = studyManagerService.getFormData(12, null, null, null);
    Assert.assertEquals("after submit there is 1 form data", 1, formData.size());
}

From source file:jhttpp2.Jhttpp2Launcher.java

public Properties loadServerProperties() {
    Properties serverproperties = new Properties();
    try {/*  w ww . j ava2 s  . c  om*/
        serverproperties.load(new DataInputStream(new FileInputStream(SERVER_PROPERTIES_FILE)));
    } catch (IOException e) {
        log.warn("failed to load the server properties", e);
    }
    return serverproperties;
}

From source file:com.googlecode.jsendnsca.NagiosPassiveCheckSender.java

public void send(MessagePayload payload) throws NagiosException, IOException {
    Validate.notNull(payload, "payload cannot be null");

    Socket socket = connectedToNagios();
    OutputStream outputStream = socket.getOutputStream();
    InputStream inputStream = socket.getInputStream();

    try {// w ww .  j  a v a2s . c o  m
        outputStream.write(passiveCheck(payload, new DataInputStream(inputStream)));
        outputStream.flush();
    } catch (SocketTimeoutException ste) {
        throw ste;
    } catch (IOException e) {
        throw new NagiosException("Error occurred while sending passive alert", e);
    } finally {
        close(socket, outputStream, inputStream);
    }
}

From source file:com.inmobi.messaging.consumer.util.MessageUtil.java

public static Text getTextMessage(byte[] line) throws IOException {
    Text text = new Text();
    ByteArrayInputStream bais = new ByteArrayInputStream(line);
    text.readFields(new DataInputStream(bais));
    return text;//from   w w w. j ava2s . c o  m
}

From source file:LCModels.MessageTransmitter.java

@Override
public void run() {
    try {//w  w  w. j a v a2s  . c o  m
        // Socket connects to the ServerSocket, ServerSocket receives a Socket, what? haha//
        //send data as points
        //            Socket s = new Socket(hostname,targetPort);
        //            Socket z = new Socket(hostname, 48500, InetAddress.getByName("127.0.0.1"), targetPort);
        Socket client = new Socket(hostname, targetPort);
        /* Get server's OutputStream */
        OutputStream outToServer = client.getOutputStream();
        /* Get server's DataOutputStream to write/send message */
        DataOutputStream out = new DataOutputStream(outToServer);
        /* Write message to DataOutputStream */
        out.writeUTF(transmitJSON.toString());
        /* Get InputStream to get message from server */
        InputStream inFromServer = client.getInputStream();
        /* Get DataInputStream to read message of server */
        DataInputStream in = new DataInputStream(inFromServer);
        /* Print message received from server */
        System.out.println("Server says..." + in.readUTF());
        client.close();
    } catch (IOException ex) {
        Logger.getLogger(MessageTransmitter.class.getName()).log(Level.SEVERE, null, ex);
    }
}