Example usage for java.io DataInputStream readFully

List of usage examples for java.io DataInputStream readFully

Introduction

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

Prototype

public final void readFully(byte b[]) throws IOException 

Source Link

Document

See the general contract of the readFully method of DataInput .

Usage

From source file:org.renjin.primitives.io.connections.Connections.java

@Internal
public static String readChar(@Current Context context, SEXP connIndex, int nchars,
        @Recycle(false) boolean useBytes) throws IOException {

    Connection conn = getConnection(context, connIndex);

    if (useBytes) {
        byte[] bytes = new byte[nchars];
        DataInputStream dis = new DataInputStream(conn.getInputStream());
        dis.readFully(bytes);
        return new String(bytes, Charsets.UTF_8);
    } else {/*from  ww  w. j  a  v  a 2 s .c o  m*/

        // it's not clear to me whether the read(char[]) methods are
        // safe to use with unicode...
        Reader in = conn.getReader();
        StringBuilder result = new StringBuilder();
        for (int i = 0; i != nchars; ++i) {
            result.appendCodePoint(in.read());
        }
        return result.toString();
    }
}

From source file:org.jboss.capedwarf.tools.BulkLoader.java

private static byte[] readArray(DataInputStream in) {
    try {/*w  w  w . j ava 2s  .  co  m*/
        int arraySize;
        try {
            arraySize = in.readInt();
        } catch (EOFException e) {
            return null;
        }
        byte[] array = new byte[arraySize];
        in.readFully(array);
        return array;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:HexUtil.java

/**
* Read a (reasonably short) BigInteger from a DataInputStream
* @param dis the stream to read from/*from  www  .j  av a 2 s. com*/
* @return a BigInteger
*/
public static BigInteger readBigInteger(DataInputStream dis) throws IOException {
    short i = dis.readShort();
    if (i < 0)
        throw new IOException("Invalid BigInteger length: " + i);
    byte[] buf = new byte[i];
    dis.readFully(buf);
    return new BigInteger(1, buf);
}

From source file:org.codice.opendx.TestNITFInputTransformer.java

private static byte[] getThumbnailBytes() throws IOException {
    DataInputStream is = new DataInputStream(new FileInputStream(
            Thread.currentThread().getContextClassLoader().getResource("binfile.dat").getFile()));
    byte[] thumbnail = new byte[is.available()];
    is.readFully(thumbnail);
    is.close();/*from   w  w w  .j  av  a  2  s  .  c om*/
    return thumbnail;
}

From source file:hudson.console.ConsoleNote.java

/**
 * Skips the encoded console note.//w  ww  .  ja v  a 2 s.c om
 */
public static void skip(DataInputStream in) throws IOException {
    byte[] preamble = new byte[PREAMBLE.length];
    in.readFully(preamble);
    if (!Arrays.equals(preamble, PREAMBLE))
        return; // not a valid preamble

    DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
    int sz = decoded.readInt();
    IOUtils.skip(decoded, sz);

    byte[] postamble = new byte[POSTAMBLE.length];
    in.readFully(postamble);
}

From source file:com.maydesk.base.util.PDUtil.java

public static byte[] readBytesFromFile(File file) throws IOException {
    byte[] bytesOfFile = new byte[(int) file.length()];
    DataInputStream dis = new DataInputStream(new FileInputStream(file));
    dis.readFully(bytesOfFile);
    dis.close();/*w  ww  . j a  va 2s  . co m*/
    return bytesOfFile;
}

From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java

private static String deserializeString(DataInputStream dis) throws IOException {
    int stringLength = dis.readInt();
    byte[] bytes = new byte[stringLength];
    dis.readFully(bytes);
    return new String(bytes);
}

From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java

private static DataBlockWriteOperation readDataBlockWriteOperation(DataInputStream in) throws IOException {
    long transactionId = in.readLong();
    long blockOffset = in.readLong();
    int len = in.readInt();
    byte[] dataBlock = new byte[len];
    in.readFully(dataBlock);

    return new DataBlockWriteOperation(transactionId, -1, blockOffset, dataBlock);
}

From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java

private static MetaDataBlockWriteOperation readMetaDataBlockWriteOperation(DataInputStream in)
        throws IOException {
    long transactionId = in.readLong();
    long metaDataOffset = in.readLong();
    int len = in.readInt();
    byte[] metaData = new byte[len];
    in.readFully(metaData);

    return new MetaDataBlockWriteOperation(transactionId, metaDataOffset, metaData);
}

From source file:hudson.console.ConsoleNote.java

/**
 * Reads a note back from {@linkplain #encodeTo(OutputStream) its encoded form}.
 *
 * @param in//w  w  w. j av a  2s.co  m
 *      Must point to the beginning of a preamble.
 *
 * @return null if the encoded form is malformed.
 */
public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {
    try {
        byte[] preamble = new byte[PREAMBLE.length];
        in.readFully(preamble);
        if (!Arrays.equals(preamble, PREAMBLE))
            return null; // not a valid preamble

        DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
        int sz = decoded.readInt();
        byte[] buf = new byte[sz];
        decoded.readFully(buf);

        byte[] postamble = new byte[POSTAMBLE.length];
        in.readFully(postamble);
        if (!Arrays.equals(postamble, POSTAMBLE))
            return null; // not a valid postamble

        ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)),
                Jenkins.getInstance().pluginManager.uberClassLoader);
        try {
            return (ConsoleNote) ois.readObject();
        } finally {
            ois.close();
        }
    } catch (Error e) {
        // for example, bogus 'sz' can result in OutOfMemoryError.
        // package that up as IOException so that the caller won't fatally die.
        throw new IOException(e);
    }
}