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:dualcontrol.CryptoClientDemo.java

private void call(Properties properties, MockableConsole console, String hostAddress, int port, byte[] data)
        throws Exception {
    Socket socket = SSLContexts.create(false, "cryptoclient.ssl", properties, console).getSocketFactory()
            .createSocket(hostAddress, port);
    DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
    dos.writeShort(data.length);//from  w  w  w  .j av  a  2  s.c  o  m
    dos.write(data);
    dos.flush();
    DataInputStream dis = new DataInputStream(socket.getInputStream());
    byte[] ivBytes = new byte[dis.readShort()];
    dis.readFully(ivBytes);
    byte[] bytes = new byte[dis.readShort()];
    dis.readFully(bytes);
    if (new String(data).contains("DECRYPT")) {
        System.err.printf("INFO CryptoClientDemo decrypted %s\n", new String(bytes));
    } else {
        System.out.printf("%s:%s\n", Base64.encodeBase64String(ivBytes), Base64.encodeBase64String(bytes));
    }
    socket.close();
}

From source file:com.cloudera.recordbreaker.hive.AvroSerDe.java

/**
 * Describe <code>deserializeRowBlob</code> method here.
 *//*from   w ww.  j a  v  a 2  s . c o  m*/
public GenericData.Record deserializeRowBlob(Writable blob) {
    byte[] rawBytes = ((Text) blob).getBytes();

    try {
        DataFileStream<GenericData.Record> dfs = new DataFileStream<GenericData.Record>(
                new DataInputStream(new ByteArrayInputStream(rawBytes)),
                new GenericDatumReader<GenericData.Record>());
        while (dfs.hasNext()) {
            return (GenericData.Record) dfs.next();
        }
    } catch (IOException iex) {
        iex.printStackTrace();
    }
    return null;
}

From source file:flens.input.SocketInput.java

@Override
public Pair<String, DataInputStream> getStream(Socket newSocket) throws IOException {
    String hostname = newSocket.getInetAddress().getHostName();
    return Pair.of(hostname, new DataInputStream(newSocket.getInputStream()));
}

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

public void readEvents(FastSelect<Event> fastSelect) throws IOException {
    LOGGER.info("Restoring events from " + eventsFile + "...");
    final long start = System.currentTimeMillis();
    List<Event> events = new ArrayList<>();

    try (DataInputStream dis = new DataInputStream(new FileInputStream(new File(dataPath, EVENTS_FILE_NAME)))) {
        try {//from   w w  w .j  a v a  2  s  .  c  o  m
            //noinspection InfiniteLoopStatement
            while (true) {
                events.add(new Event(dis.readShort(), dis.readLong(), dis.readLong()));
                if (events.size() > 1000)
                    batchAdd(fastSelect, events);
            }
        } catch (EOFException e) {
            // just end
        }
    } catch (FileNotFoundException e) {
        // nothing, just no data
    }
    batchAdd(fastSelect, events);

    LOGGER.info(fastSelect.size() + " restored in " + (System.currentTimeMillis() - start) + " msec");
}

From source file:TestGetXMLClient.java

public void testXML() throws Exception {
    Collection<Class> classList = getClasses();
    String serverUrl = "@SERVER_URL@";
    for (Class klass : classList) {
        System.out.println("Searching for " + klass.getName());
        try {/*from   w ww .java  2  s  .c  om*/
            String searchUrl = serverUrl + "/GetXML?query=" + klass.getName() + "&" + klass.getName();
            URL url = new URL(searchUrl);
            URLConnection conn = url.openConnection();

            //Uncomment following two lines for secured system and provide proper username and password
            //String base64 = "userId" + ":" + "password";
            //conn.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

            File myFile = new File("./output/" + klass.getName() + "_test-getxml.xml");

            FileWriter myWriter = new FileWriter(myFile);
            DataInputStream dis = new DataInputStream(conn.getInputStream());

            String s = null;
            while ((s = dis.readLine()) != null)
                myWriter.write(s);

            myWriter.close();
        } catch (Exception e) {
            System.out.println("Exception caught: " + e.getMessage());
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.google.gwt.dev.javac.CachedCompilationUnit.java

public static CachedCompilationUnit load(InputStream inputStream, JsProgram jsProgram) throws Exception {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream));
    try {// w w  w . j ava 2  s. c  om
        CachedCompilationUnit compilationUnit = new CachedCompilationUnit();
        // version
        long version = dis.readLong();
        if (version != CompilationUnitDiskCache.CACHE_VERSION) {
            return null;
        }
        // some simple stuff :)
        compilationUnit.m_lastModified = dis.readLong();
        compilationUnit.m_displayLocation = dis.readUTF();
        compilationUnit.m_typeName = dis.readUTF();
        compilationUnit.m_contentId = new ContentId(dis.readUTF());
        compilationUnit.m_isSuperSource = dis.readBoolean();
        // compiled classes
        {
            int size = dis.readInt();
            compilationUnit.m_compiledClasses = new ArrayList<CompiledClass>(size);
            for (int i = 0; i < size; ++i) {
                // internal name
                String internalName = dis.readUTF();
                // is local
                boolean isLocal = dis.readBoolean();
                // bytes
                int byteSize = dis.readInt();
                byte[] bytes = new byte[byteSize];
                dis.readFully(bytes);
                // enclosing class
                CompiledClass enclosingClass = null;
                String enclosingClassName = dis.readUTF();
                if (!StringUtils.isEmpty(enclosingClassName)) {
                    for (CompiledClass cc : compilationUnit.m_compiledClasses) {
                        if (enclosingClassName.equals(cc.getInternalName())) {
                            enclosingClass = cc;
                            break;
                        }
                    }
                }
                // some assertion
                if (!StringUtils.isEmpty(enclosingClassName) && enclosingClass == null) {
                    throw new IllegalStateException("Can't find the enclosing class \"" + enclosingClassName
                            + "\" for \"" + internalName + "\"");
                }
                // init unit
                CompiledClass cc = new CompiledClass(internalName, bytes, isLocal, enclosingClass);
                cc.initUnit(compilationUnit);
                compilationUnit.m_compiledClasses.add(cc);
            }
        }
        // dependencies
        {
            compilationUnit.m_dependencies = new HashSet<ContentId>();
            int size = dis.readInt();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    compilationUnit.m_dependencies.add(new ContentId(dis.readUTF()));
                }
            }
        }
        // JSNI methods
        {
            compilationUnit.m_jsniMethods = new ArrayList<JsniMethod>();
            int size = dis.readInt();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    String name = dis.readUTF();
                    int startPos = dis.readInt();
                    int endPos = dis.readInt();
                    int startLine = dis.readInt();
                    String source = dis.readUTF();
                    String fileName = compilationUnit.m_displayLocation;
                    SourceInfo jsInfo = SourceOrigin.create(startPos, endPos, startLine, fileName);
                    compilationUnit.m_jsniMethods
                            .add(JsniCollector.restoreJsniMethod(name, source, jsInfo, jsProgram));
                }
            }
        }
        // Method lookup
        {
            compilationUnit.m_methodArgs = MethodArgNamesLookup.load(dis);
        }
        return compilationUnit;
    } finally {
        IOUtils.closeQuietly(dis);
    }
}

From source file:bankingclient.DKFrame.java

public DKFrame(MainFrame vmain) {
    initComponents();//from  www.ja  v a2 s . c o  m
    this.main = vmain;
    this.jTextField1.setText("");
    this.jTextField2.setText("");
    this.jTextField3.setText("");
    this.jTextField4.setText("");
    this.jTextField5.setText("");
    this.setVisible(false);
    jButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (jTextField2.getText().equals(jTextField3.getText())
                    && NumberUtils.isNumber(jTextField4.getText())
                    && NumberUtils.isNumber(jTextField5.getText())) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    String cusName = jTextField1.getText();
                    String pass = jTextField2.getText();
                    String sdt = jTextField4.getText();
                    String cmt = jTextField5.getText();
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(1);
                    dout.writeUTF(cusName + "\n" + pass + "\n" + sdt + "\n" + cmt);
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        JOptionPane.showMessageDialog(rootPane, "da dang ki tai khoan thanh cong");
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "dang ki tai khoan khong thanh cong");

                    }
                    client.close();
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
                main.setVisible(true);
                DKFrame.this.setVisible(false);

            } else {
                JOptionPane.showMessageDialog(rootPane, "Nhap thong tin sai, moi nhap lai");
            }
        }
    });
    jButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            main.setVisible(true);
            DKFrame.this.setVisible(false);
        }
    });
}

From source file:com.spotify.scio.coders.FloatCoder.java

@Override
public Float decode(InputStream inStream, Context context) throws IOException, CoderException {
    try {//from   ww w .  j a  v a2  s  .com
        return new DataInputStream(inStream).readFloat();
    } catch (EOFException | UTFDataFormatException exn) {
        // These exceptions correspond to decoding problems, so change
        // what kind of exception they're branded as.
        throw new CoderException(exn);
    }
}

From source file:Main.java

public static int[] convertB64Toint(byte[] a1) {
    byte[] a = decode(a1);
    try {/*from ww  w .  ja va2  s.com*/
        ByteArrayInputStream is = new ByteArrayInputStream(a1);
        DataInputStream di = new DataInputStream(is);
        int[] f = new int[a.length / 4];
        for (int i = 0; i < f.length; i++)
            f[i] = di.readInt();
        return f;
    } catch (Exception s) {
        return null;
    }

}

From source file:Main.java

public static float[] convertB64Tofloat(byte[] a1) {
    byte[] a = decode(a1);
    try {//www.  ja v  a  2 s  . c o  m
        ByteArrayInputStream is = new ByteArrayInputStream(a);
        DataInputStream di = new DataInputStream(is);
        float[] f = new float[a.length / 4];
        for (int i = 0; i < f.length; i++)
            f[i] = di.readFloat();
        return f;
    } catch (Exception s) {
        return null;
    }
}