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:com.zjy.mongo.util.BSONLoader.java

public BSONLoader(final InputStream input) {
    this.input = new DataInputStream(input);
}

From source file:com.cuubez.visualizer.scanner.ClassScanner.java

public List<Class<?>> scan(String applicationPath) throws IOException {

    List<Class<?>> classes = new ArrayList<Class<?>>();

    URL resource = findResources(applicationPath);
    FileReader itr = getFileReader(resource, new ClassFileFilter());

    InputStream is;/*  w  w w  .ja v  a 2s .c om*/
    while ((is = itr.next()) != null) {
        // make a data input stream
        DataInputStream dstream = new DataInputStream(new BufferedInputStream(is));

        try {
            // get java-assist class file
            ClassFile classFile = new ClassFile(dstream);
            classes.add(Class.forName(classFile.getName()));

        } catch (ClassNotFoundException e) {
            log.error(e);
        } finally {
            dstream.close();
            is.close();
        }
    }

    return classes;
}

From source file:com.microsoft.tfs.client.eclipse.resourcedata.ResourceData.java

/**
 * Deserializes a {@link ResourceData} object from a byte array.
 *
 * @param value//from   w  w  w .  j a  va  2s  .  c om
 *        the byte array (not null)
 * @return the deserialized {@link ResourceData} or <code>null</code> if
 *         there was a problem deserializing
 */
public static ResourceData fromByteArray(final byte[] value) {
    Check.notNull(value, "value"); //$NON-NLS-1$

    try {
        final ByteArrayInputStream is = new ByteArrayInputStream(value);
        final DataInputStream dis = new DataInputStream(is);

        return new ResourceData(dis.readUTF(), dis.readInt());
    } catch (final IOException e) {
        log.error("Error deserializing", e); //$NON-NLS-1$
        return null;
    }
}

From source file:ImportKey.java

/**
 * <p>/* w ww. ja  va2s.c o m*/
 * Creates an InputStream from a file, and fills it with the complete file.
 * Thus, available() on the returned InputStream will return the full number
 * of bytes the file contains
 * </p>
 * 
 * @param fname
 *            The filename
 * @return The filled InputStream
 * @exception IOException
 *                , if the Streams couldn't be created.
 **/
private static InputStream fullStream(String fname) throws IOException {
    FileInputStream fis = new FileInputStream(fname);
    DataInputStream dis = new DataInputStream(fis);
    byte[] bytes = new byte[dis.available()];
    dis.readFully(bytes);
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    return bais;
}

From source file:bankingclient.TaoTaiKhoanFrame.java

public TaoTaiKhoanFrame(NewOrOldAccFrame acc) {

    initComponents();/*from w  w  w. j av  a2  s  .co m*/
    this.jText_ten_tk.setText("");
    this.jText_sd.setText("");

    this.noAcc = acc;
    this.mainCustomerName = null;
    this.setVisible(false);

    jBt_ht.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (NumberUtils.isNumber(jText_sd.getText()) && (Long.parseLong(jText_sd.getText()) > 0)) {
                try {
                    Socket client = new Socket("113.22.46.207", 6013);
                    DataOutputStream dout = new DataOutputStream(client.getOutputStream());
                    dout.writeByte(3);
                    dout.writeUTF(jText_ten_tk.getText() + "\n" + mainCustomerName + "\n" + jText_sd.getText());
                    dout.flush();
                    DataInputStream din = new DataInputStream(client.getInputStream());
                    byte check = din.readByte();
                    if (check == 1) {
                        JOptionPane.showMessageDialog(rootPane, "da tao tai khoan thanh cong");
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "tao tai khoan khong thanh cong");
                    }
                    client.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                noAcc.setVisible(true);
                TaoTaiKhoanFrame.this.setVisible(false);
            } else {
                JOptionPane.showMessageDialog(rootPane, "Can nhap lai so tien gui");
            }

        }
    });
    jBt_ql.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            noAcc.setVisible(true);
            TaoTaiKhoanFrame.this.setVisible(false);

        }
    });
}

From source file:gobblin.util.io.MeteredInputStreamTest.java

@Test
public void test() throws Exception {
    InputStream is = new ByteArrayInputStream("aabbccddee".getBytes(Charsets.UTF_8));

    Meter meter = new Meter();
    MeteredInputStream mis = MeteredInputStream.builder().in(is).meter(meter).updateFrequency(1).build();

    InputStream skipped = new MyInputStream(mis);
    DataInputStream dis = new DataInputStream(skipped);

    ByteArrayOutputStream os = new ByteArrayOutputStream();

    IOUtils.copy(dis, os);/* ww  w  .  java2  s. c  o m*/
    String output = os.toString(Charsets.UTF_8.name());

    Assert.assertEquals(output, "abcde");

    Optional<MeteredInputStream> meteredOpt = MeteredInputStream.findWrappedMeteredInputStream(dis);
    Assert.assertEquals(meteredOpt.get(), mis);
    Assert.assertEquals(meteredOpt.get().getBytesProcessedMeter().getCount(), 10);
}

From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java

public PersistentCookieStore(final byte[] data) throws IOException {

    final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));

    final int len = dis.readInt();

    for (int i = 0; i < len; i++) {

        final String name = dis.readUTF();
        final String value = dis.readUTF();
        final String domain = dis.readUTF();
        final String path = dis.readUTF();
        final boolean isSecure = dis.readBoolean();

        final BasicClientCookie cookie = new BasicClientCookie(name, value);
        cookie.setDomain(domain);/*from w  w  w .  ja v  a2s  . com*/
        cookie.setPath(path);
        cookie.setSecure(isSecure);

        cookies.add(cookie);
    }
}

From source file:com.px100systems.util.serialization.DataStream.java

public DataStream(byte[] data) {
    dis = new DataInputStream(new ByteArrayInputStream(data));
}

From source file:gaffer.serialisation.implementation.raw.CompactRawLongSerialiserTest.java

private static void test(final long value) throws SerialisationException {
    final byte[] b = SERIALISER.serialise(value);
    final Object o = SERIALISER.deserialise(b);
    assertEquals(Long.class, o.getClass());
    assertEquals(value, o);// ww  w  .j a va 2  s .com
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CompactRawSerialisationUtils.write(value, new DataOutputStream(baos));
    final long result = CompactRawSerialisationUtils
            .read(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
    assertEquals(result, value);
}

From source file:com.mulesoft.example.fileconsumer.FileConsumerTestCase.java

@Test
public void fileConsumer() throws Exception {
    MuleClient client = muleContext.getClient();

    String sourceFileName = "sourceTestFile.csv";
    URL url = IOUtils.getResourceAsUrl(sourceFileName, getClass());
    FileUtils.copyFile(new File(url.toURI()),
            new File(properties.getProperty("FileConsumer.sourceFolder") + "/" + sourceFileName));

    FileInputStream file = new FileInputStream(new File(url.toURI()));
    DataInputStream is = new DataInputStream(file);
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line;/*from   w  w  w.  j a va 2  s. c  om*/
    try {
        while ((line = br.readLine()) != null) {
            MuleMessage result = client.request("vm://" + properties.getProperty("FileConsumer.stockDataTopic"),
                    RECEIVE_TIMEOUT);
            assertNotNull(result);
            assertFalse(result.getPayload() instanceof NullPayload);

            String[] split = line.split(",");
            String payload = result.getPayloadAsString();
            for (String item : split) {
                assertTrue(payload.contains(item));
            }
        }
    } finally {
        is.close();
    }
}