Example usage for java.io DataInputStream readUTF

List of usage examples for java.io DataInputStream readUTF

Introduction

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

Prototype

public final String readUTF() throws IOException 

Source Link

Document

See the general contract of the readUTF method of DataInput.

Usage

From source file:com.bigdata.dastor.db.RowMutation.java

public RowMutation deserialize(DataInputStream dis) throws IOException {
    String table = dis.readUTF();
    String key = dis.readUTF();//from  www . java  2 s .  com
    Map<String, ColumnFamily> modifications = defreezeTheMaps(dis);
    return new RowMutation(table, key, modifications);
}

From source file:J2MEWriteReadMixedDataTypesExample.java

public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
        destroyApp(true);// ww w .ja  v  a2s  .  c o m
        notifyDestroyed();
    } else if (command == start) {
        try {
            recordstore = RecordStore.openRecordStore("myRecordStore", true);
            byte[] outputRecord;
            String outputString = "First Record";
            int outputInteger = 15;
            boolean outputBoolean = true;
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            DataOutputStream outputDataStream = new DataOutputStream(outputStream);
            outputDataStream.writeUTF(outputString);
            outputDataStream.writeBoolean(outputBoolean);
            outputDataStream.writeInt(outputInteger);
            outputDataStream.flush();
            outputRecord = outputStream.toByteArray();
            recordstore.addRecord(outputRecord, 0, outputRecord.length);
            outputStream.reset();
            outputStream.close();
            outputDataStream.close();
            String inputString = null;
            int inputInteger = 0;
            boolean inputBoolean = false;
            byte[] byteInputData = new byte[100];
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
            DataInputStream inputDataStream = new DataInputStream(inputStream);
            for (int x = 1; x <= recordstore.getNumRecords(); x++) {
                recordstore.getRecord(x, byteInputData, 0);
                inputString = inputDataStream.readUTF();
                inputBoolean = inputDataStream.readBoolean();
                inputInteger = inputDataStream.readInt();
                inputStream.reset();
            }
            inputStream.close();
            inputDataStream.close();
            alert = new Alert("Reading", inputString + " " + inputInteger + " " + inputBoolean, null,
                    AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
            recordstore.closeRecordStore();
            if (RecordStore.listRecordStores() != null) {
                RecordStore.deleteRecordStore("myRecordStore");
            }
        } catch (Exception error) {
            alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
    }
}

From source file:com.towerlabs.yildizyemek.ViewPagerDinner.java

public String readFile() throws IOException {

    FileInputStream fi;//from www . ja  va 2 s  . c o m
    DataInputStream di;
    String result = null;

    fi = new FileInputStream(file);
    di = new DataInputStream(fi);

    result = di.readUTF();

    fi.close();
    di.close();

    fi = null;
    di = null;

    return result;

}

From source file:com.facebook.infrastructure.db.Column.java

/**
 * Here we need to get the column and apply the filter.
 *///from   www.ja  va2  s.c  om
public IColumn deserialize(DataInputStream dis, IFilter filter) throws IOException {
    if (dis.available() == 0)
        return null;

    String name = dis.readUTF();
    IColumn column = new Column(name);
    column = filter.filter(column, dis);
    if (column != null) {
        column = defreeze(dis, name);
    } else {
        /* Skip a boolean and the timestamp */
        dis.skip(DBConstants.boolSize_ + DBConstants.tsSize_);
        int size = dis.readInt();
        dis.skip(size);
    }
    return column;
}

From source file:org.nuxeo.osgi.BundleIdGenerator.java

public synchronized void load(File file) {
    DataInputStream in = null;
    try {//from ww w  .ja va 2 s. c o m
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
        count = in.readLong();
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            String key = in.readUTF();
            long id = in.readLong();
            ids.put(key, id);
        }
    } catch (FileNotFoundException e) {
        // do nothing - this is the first time the runtime is started
    } catch (IOException e) {
        // may be the file is corrupted
        file.delete();
        log.error("The bundle.ids file is corrupted. reseting bundle ids.");
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java

private void fromInputStream(InputStream input) throws IOException {
    DataInputStream dis = new DataInputStream(input);

    long version = dis.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }//w ww . j a va 2s  .c o  m

    algorithm = dis.readUTF();

    int saltSize = dis.readInt();

    this.salt = new byte[saltSize];

    dis.readFully(salt);

    this.iterationCount = dis.readInt();
}

From source file:com.yahoo.pulsar.testclient.LoadSimulationClient.java

private void decodeProducerOptions(final TradeConfiguration tradeConf, final DataInputStream inputStream)
        throws Exception {
    tradeConf.topic = inputStream.readUTF();
    tradeConf.size = inputStream.readInt();
    tradeConf.rate = inputStream.readDouble();
}

From source file:com.yahoo.pulsar.testclient.LoadSimulationClient.java

private void decodeGroupOptions(final TradeConfiguration tradeConf, final DataInputStream inputStream)
        throws Exception {
    tradeConf.tenant = inputStream.readUTF();
    tradeConf.group = inputStream.readUTF();
}

From source file:FilterFieldsMIDlet.java

public boolean matches(byte[] candidate) {
    DataInputStream student = new DataInputStream(new ByteArrayInputStream(candidate));
    int average = 0;
    try {/*w w w  .j  a v a 2s .com*/
        String dummy = student.readUTF();
        average = (student.readInt() + student.readInt() + student.readInt()) / 3;

    } catch (Exception e) {
    }
    if (average >= 80)
        return true;
    else
        return false;

}

From source file:org.eclipse.orion.internal.server.search.SearchActivator.java

/**
 * Returns the generation number of the current index on disk.
 * //  ww w . j ava  2  s  .  c o  m
 * @return the current index generation, or -1 if no index was found.
 */
private int readIndexGeneration(File baseDir) {
    File generationFile = new File(baseDir, INDEX_GENERATION_FILE);
    if (!generationFile.exists())
        return -1;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(generationFile));
        int generation = Integer.valueOf(in.readUTF());
        return generation;
    } catch (Exception e) {
        // ignore and return false below
    } finally {
        IOUtilities.safeClose(in);
    }
    return -1;
}