Example usage for java.io DataInputStream read

List of usage examples for java.io DataInputStream read

Introduction

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

Prototype

public final int read(byte b[]) throws IOException 

Source Link

Document

Reads some number of bytes from the contained input stream and stores them into the buffer array b.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/Array.txt");
    DataInputStream din = new DataInputStream(fin);

    byte b[] = new byte[10];
    din.read(b);
    din.close();//  ww w.  j a va2s  .  c o m
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    int count = is.available();

    byte[] bs = new byte[count];

    dis.read(bs);

    for (byte b : bs) {
        char c = (char) b;
        System.out.print(c);//from ww w.j  a v  a2s. c  o m
    }

}

From source file:Main.java

public static void main(String[] atgs) throws Exception {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java.txt")));
    out.writeUTF("");
    out.writeBytes("a");
    out.writeChars("aaa");
    out.close();//from  ww  w. ja v  a  2s .  c  o  m
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("java.txt")));
    System.out.println(in.readUTF());
    byte[] buf = new byte[1024];
    int len = in.read(buf);
    System.out.println(new String(buf, 0, len));
    in.close();
}

From source file:Version2LicenseDecoder.java

public static void main(String[] args) throws IOException, Exception {
    new Version2LicenseDecoder();
    String lll = "AAABDA0ODAoPeNptUEtPg0AQvu+vIPG8ZsEKlmQPFda6DVAENB68rHTUbdotmQVi/71QTHykh5lM5nvMl7m4Q+2sOuOwwGHz8PomnDFnmVaOx9wrEoOtUTetPhi+ksXiJXREr3adGjckQjgNsWqBj3zKfMoCstWoLhNdg7EgNvqkFlkliryQpSA/DrzFDv7Qq2MDmdoDj9ZpKopILpIJV3Wre5gEu4n7BGhHE4+kSpsWjDI1iM9G4/FXomBMtMZ3ZbSdjm4PWpnN0M1knXX7V8D126MdDDl1SQnYA8qY31b5A5WRLKgfP0d0du8uSSkyPhRNPJ/5njcn38kHeiLjc8j5SHmH9Yey8P95XxVof60wKwITfDIxHZPgo323OEKd2FJ4BXvU7wIUIbLvXQNrkIAf4AL2Aeu4ZBRbTOA=X02dl";
    String lls = "AAABckRlc2NyaXB0aW9uPUpJUkE6IENvbW1lcmNpYWwKQ3JlYXRpb25EYXRlPTIwMTMtMDYtMDcKamlyYS5MaWNlbnNlRWRpdGlvbj1FTlRFUlBSSVNFCkV2YWx1YXRpb249ZmFsc2UKamlyYS5MaWNlbnNlVHlwZU5hbWU9Q09NTUVSQ0lBTApqaXJhLmFjdGl2ZT10cnVlCmxpY2Vuc2VWZXJzaW9uPTIKTWFpbnRlbmFuY2VFeHBpcnlEYXRlPTIwOTktMDYtMDcKT3JnYW5pc2F0aW9uPWpvaWFuZGpvaW4KU0VOPVNFTi1MMjYwNjIyOQpTZXJ2ZXJJRD1CVFBRLUlDSVItNkRYQy00SDFHCmppcmEuTnVtYmVyT2ZVc2Vycz0tMQpMaWNlbnNlSUQ9TElEU0VOLUwyNjA2MjI5CkxpY2Vuc2VFeHBpcnlEYXRlPTIwOTktMDYtMDcKUHVyY2hhc2VEYXRlPTIwMTMtMDYtMDc=X02g4";
    //      String sll = "Description=JIRA:Commercial\nCreationDate=2013-06-07\njira.LicenseEdition=ENTERPRISE\nEvaluation=false\njira.LicenseTypeName=COMMERCIAL\njira.active=true\nlicenseVersion=2\nMaintenanceExpiryDate=2099-06-07\nOrganisation=joiandjoin\nSEN=SEN-L2606229\nServerID=BTPQ-ICIR-6DXC-4H1G\njira.NumberOfUsers=-1\nLicenseID=LIDSEN-L2606229\nLicenseExpiryDate=2099-06-07\nPurchaseDate=2013-06-07";
    //      String sll = "com.allenta.jira.plugins.gitlab.gitlab-listener.enterprise=true\nDescription=GitLab Listener\\: Evaluation\nNumberOfUsers=-1\nCreationDate=2015-12-29\nContactEMail=xwturing@gmail.com\nEvaluation=true\ncom.allenta.jira.plugins.gitlab.gitlab-listener.Starter=false\nlicenseVersion=2\nMaintenanceExpiryDate=2099-01-27\nOrganisation=Evaluation license\nSEN=SEN-L7030895\ncom.allenta.jira.plugins.gitlab.gitlab-listener.active=true\nLicenseExpiryDate=2099-01-27\nLicenseTypeName=COMMERCIAL\nPurchaseDate=2015-12-29\n";
    //      String sll = "jira.product.jira-servicedesk.active=true\njira.product.jira-servicedesk.Starter=false\nNumberOfUsers=-1\nPurchaseDate=2016-01-05\ncom.atlassian.servicedesk.active=true\nLicenseTypeName=COMMERCIAL\nLicenseExpiryDate=2099-02-03\nContactEMail=xwturing@gmail.com\nServerID=BWGW-FKTG-N1UQ-PNHH\ncom.atlassian.servicedesk.LicenseTypeName=COMMERCIAL\njira.product.jira-servicedesk.NumberOfUsers=-1\nMaintenanceExpiryDate=2099-02-03\ncom.atlassian.servicedesk.enterprise=true\nLicenseID=LIDSEN-L7059162\nSEN=SEN-L7059162\nOrganisation=Evaluation license\nCreationDate=2016-01-05\ncom.atlassian.servicedesk.numRoleCount=-1\nlicenseVersion=2\nDescription=JIRA Service Desk (Server)\\: Evaluation\nEvaluation=true";
    String sll = "NumberOfUsers=-1\n" + "jira.product.jira-core.NumberOfUsers=-1\n" + "jira.NumberOfUsers=-1\n"
            + "PurchaseDate=2016-02-20\n" + "LicenseTypeName=COMMERCIAL\n" + "LicenseExpiryDate=2099-03-21\n"
            + "ContactEMail=xwturing@gmail.com\n" + "ServerID=BVDW-Q5Y0-CRXH-AI3I\n"
            + "jira.product.jira-core.Starter=false\n" + "jira.LicenseEdition=ENTERPRISE\n"
            + "jira.product.jira-core.active=true\n" + "MaintenanceExpiryDate=2099-03-21\n"
            + "LicenseID=LIDSEN-L7336401\n" + "SEN=SEN-L7336401\n" + "Organisation=Evaluation license\n"
            + "CreationDate=2016-02-20\n" + "licenseVersion=2\n"
            + "Description=JIRA Core (Server)\\: Evaluation\n" + "jira.active=true\n"
            + "jira.LicenseTypeName=COMMERCIAL\n" + "Evaluation=true";

    byte[] allData = sll.getBytes();
    Signature signature = Signature.getInstance("SHA1withDSA");
    signature.initVerify(PUBLIC_KEY);//w  ww .  j  a va2 s .c o  m
    signature.update(allData);
    ByteArrayInputStream in = new ByteArrayInputStream(allData);
    DataInputStream dIn = new DataInputStream(in);
    int textLength = dIn.readInt();
    byte[] licenseText = new byte[textLength];
    dIn.read(licenseText);
    byte[] hash = new byte[dIn.available()];
    dIn.read(hash);
    String result = packLicense(allData, hash);
    System.out.println(result);
}

From source file:webcamstream.ClientConnection.java

public static void main(String... a) throws IOException {
    Socket cs = new Socket("localhost", SERVER_PORT);
    System.out.println("socket created");
    DataInputStream ci = new DataInputStream(cs.getInputStream());
    DataOutputStream co = new DataOutputStream(cs.getOutputStream());

    //sending negotiaiton to the server
    Message m = new Message(FieldValues.STARTSTREAM.getValue(), FieldValues.FORMAT.getValue(), width, height);
    co.writeUTF(m.toJSONString());/* www  .j  a v a 2 s  .c  o m*/

    byte[] base64 = new byte[width * height * 3];
    while (true) {

        byte[] msgBytes = new byte[base64.length + 2048];
        ci.read(msgBytes);
        System.out.println(new String(msgBytes));
        Message sm = Message.parseJSONString(new String(msgBytes).trim());

        //decode an image
        byte[] compressedImage = Base64.decodeBase64(base64);
        //decompressing an image       
        byte[] decompressedImage = Compressor.decompress(compressedImage);

        System.out.println(decompressedImage.length);
    }

}

From source file:com.splout.db.dnode.TCPStreamer.java

/**
 * This main method can be used for testing the TCP interface directly to a
 * local DNode. Will ask for protocol input from Stdin and print output to
 * Stdout/*w w  w.  ja va 2  s  .c om*/
 */
public static void main(String[] args) throws UnknownHostException, IOException, SerializationException {
    SploutConfiguration config = SploutConfiguration.get();
    Socket clientSocket = new Socket("localhost", config.getInt(DNodeProperties.STREAMING_PORT));

    DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream()));
    DataOutputStream outToServer = new DataOutputStream(
            new BufferedOutputStream(clientSocket.getOutputStream()));

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter tablespace: ");
    String tablespace = reader.readLine();

    System.out.println("Enter version number: ");
    long versionNumber = Long.parseLong(reader.readLine());

    System.out.println("Enter partition: ");
    int partition = Integer.parseInt(reader.readLine());

    System.out.println("Enter query: ");
    String query = reader.readLine();

    outToServer.writeUTF(tablespace);
    outToServer.writeLong(versionNumber);
    outToServer.writeInt(partition);
    outToServer.writeUTF(query);

    outToServer.flush();

    byte[] buffer = new byte[0];
    boolean read;
    do {
        read = false;
        int nBytes = inFromServer.readInt();
        if (nBytes > 0) {
            buffer = new byte[nBytes];
            int inRead = inFromServer.read(buffer);
            if (inRead > 0) {
                Object[] res = ResultSerializer.deserialize(ByteBuffer.wrap(buffer), Object[].class);
                read = true;
                System.out.println(Arrays.toString(res));
            }
        }
    } while (read);

    clientSocket.close();
}

From source file:org.nuxeo.theme.styling.service.palettes.PaletteParser.java

public static Map<String, String> parse(InputStream in, String filename)
        throws IOException, PaletteParseException {
    DataInputStream dis = new DataInputStream(in);
    byte[] bytes = new byte[dis.available()];
    dis.read(bytes);
    return parse(bytes, filename);
}

From source file:Main.java

public static byte[] readToEndAsArray(InputStream input) throws IOException {
    DataInputStream dis = new DataInputStream(input);
    byte[] stuff = new byte[1024];
    ByteArrayOutputStream buff = new ByteArrayOutputStream();
    int read = 0;
    while ((read = dis.read(stuff)) != -1) {
        buff.write(stuff, 0, read);//from  ww w . j ava 2s.  c o  m
    }
    dis.close();
    return buff.toByteArray();
}

From source file:com.opensoc.json.serialization.JSONDecoderHelper.java

public static String getString(DataInputStream data) throws IOException {

    int strSize = data.readInt();

    byte[] bytes = new byte[strSize];
    data.read(bytes);
    return new String(bytes);
}

From source file:Main.java

protected static byte[] deserialiseByteArray(DataInputStream is, int max_length)

        throws IOException {
    int len = deserialiseLength(is, max_length);

    byte[] data = new byte[len];

    is.read(data);

    return (data);
}