Search in sources :

Example 81 with DataInputStream

use of java.io.DataInputStream in project Gaffer by gchq.

the class FilterWritabilityTest method shouldWriteAndReadFilter.

@Test
public void shouldWriteAndReadFilter() throws IOException {
    // Given
    final BloomFilter filter = new BloomFilter(100, 5, Hash.MURMUR_HASH);
    filter.add(new Key("ABC".getBytes()));
    filter.add(new Key("DEF".getBytes()));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final DataOutputStream out = new DataOutputStream(baos);
    filter.write(out);
    String x = new String(baos.toByteArray(), AccumuloStoreConstants.BLOOM_FILTER_CHARSET);
    final ByteArrayInputStream bais = new ByteArrayInputStream(x.getBytes(AccumuloStoreConstants.BLOOM_FILTER_CHARSET));
    // When
    final DataInputStream in = new DataInputStream(bais);
    final BloomFilter read = new BloomFilter();
    read.readFields(in);
    // Then
    assertTrue(read.membershipTest(new Key("ABC".getBytes())));
    assertTrue(read.membershipTest(new Key("DEF".getBytes())));
    assertFalse(read.membershipTest(new Key("lkjhgfdsa".getBytes())));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) BloomFilter(org.apache.accumulo.core.bloomfilter.BloomFilter) Key(org.apache.hadoop.util.bloom.Key) Test(org.junit.Test)

Example 82 with DataInputStream

use of java.io.DataInputStream in project Gaffer by gchq.

the class CompactRawLongSerialiserTest method test.

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);
    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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 83 with DataInputStream

use of java.io.DataInputStream in project XobotOS by xamarin.

the class RIL method sendCdmaSms.

public void sendCdmaSms(byte[] pdu, Message result) {
    int address_nbr_of_digits;
    int subaddr_nbr_of_digits;
    int bearerDataLength;
    ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
    DataInputStream dis = new DataInputStream(bais);
    RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SEND_SMS, result);
    try {
        //teleServiceId
        rr.mp.writeInt(dis.readInt());
        //servicePresent
        rr.mp.writeByte((byte) dis.readInt());
        //serviceCategory
        rr.mp.writeInt(dis.readInt());
        //address_digit_mode
        rr.mp.writeInt(dis.read());
        //address_nbr_mode
        rr.mp.writeInt(dis.read());
        //address_ton
        rr.mp.writeInt(dis.read());
        //address_nbr_plan
        rr.mp.writeInt(dis.read());
        address_nbr_of_digits = (byte) dis.read();
        rr.mp.writeByte((byte) address_nbr_of_digits);
        for (int i = 0; i < address_nbr_of_digits; i++) {
            // address_orig_bytes[i]
            rr.mp.writeByte(dis.readByte());
        }
        //subaddressType
        rr.mp.writeInt(dis.read());
        //subaddr_odd
        rr.mp.writeByte((byte) dis.read());
        subaddr_nbr_of_digits = (byte) dis.read();
        rr.mp.writeByte((byte) subaddr_nbr_of_digits);
        for (int i = 0; i < subaddr_nbr_of_digits; i++) {
            //subaddr_orig_bytes[i]
            rr.mp.writeByte(dis.readByte());
        }
        bearerDataLength = dis.read();
        rr.mp.writeInt(bearerDataLength);
        for (int i = 0; i < bearerDataLength; i++) {
            //bearerData[i]
            rr.mp.writeByte(dis.readByte());
        }
    } catch (IOException ex) {
        if (RILJ_LOGD)
            riljLog("sendSmsCdma: conversion from input stream to object failed: " + ex);
    }
    if (RILJ_LOGD)
        riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    send(rr);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 84 with DataInputStream

use of java.io.DataInputStream in project XobotOS by xamarin.

the class GestureStore method load.

public void load(InputStream stream, boolean closeStream) throws IOException {
    DataInputStream in = null;
    try {
        in = new DataInputStream((stream instanceof BufferedInputStream) ? stream : new BufferedInputStream(stream, GestureConstants.IO_BUFFER_SIZE));
        long start;
        if (PROFILE_LOADING_SAVING) {
            start = SystemClock.elapsedRealtime();
        }
        // Read file format version number
        final short versionNumber = in.readShort();
        switch(versionNumber) {
            case 1:
                readFormatV1(in);
                break;
        }
        if (PROFILE_LOADING_SAVING) {
            long end = SystemClock.elapsedRealtime();
            Log.d(LOG_TAG, "Loading gestures library = " + (end - start) + " ms");
        }
    } finally {
        if (closeStream)
            GestureUtils.closeStream(in);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream)

Example 85 with DataInputStream

use of java.io.DataInputStream in project XobotOS by xamarin.

the class ZipFile method getInputStream.

/**
     * Returns an input stream on the data of the specified {@code ZipEntry}.
     *
     * @param entry
     *            the ZipEntry.
     * @return an input stream of the data contained in the {@code ZipEntry}.
     * @throws IOException
     *             if an {@code IOException} occurs.
     * @throws IllegalStateException if this ZIP file has been closed.
     */
public InputStream getInputStream(ZipEntry entry) throws IOException {
    // Make sure this ZipEntry is in this Zip file.  We run it through the name lookup.
    entry = getEntry(entry.getName());
    if (entry == null) {
        return null;
    }
    // Create an InputStream at the right part of the file.
    RandomAccessFile raf = mRaf;
    synchronized (raf) {
        // We don't know the entry data's start position. All we have is the
        // position of the entry's local header. At position 28 we find the
        // length of the extra data. In some cases this length differs from
        // the one coming in the central header.
        RAFStream rafstrm = new RAFStream(raf, entry.mLocalHeaderRelOffset + 28);
        DataInputStream is = new DataInputStream(rafstrm);
        int localExtraLenOrWhatever = Short.reverseBytes(is.readShort());
        is.close();
        // Skip the name and this "extra" data or whatever it is:
        rafstrm.skip(entry.nameLength + localExtraLenOrWhatever);
        rafstrm.mLength = rafstrm.mOffset + entry.compressedSize;
        if (entry.compressionMethod == ZipEntry.DEFLATED) {
            int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
            return new ZipInflaterInputStream(rafstrm, new Inflater(true), bufSize, entry);
        } else {
            return rafstrm;
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) DataInputStream(java.io.DataInputStream)

Aggregations

DataInputStream (java.io.DataInputStream)1544 ByteArrayInputStream (java.io.ByteArrayInputStream)635 IOException (java.io.IOException)582 DataOutputStream (java.io.DataOutputStream)315 FileInputStream (java.io.FileInputStream)313 Test (org.junit.Test)274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)198 BufferedInputStream (java.io.BufferedInputStream)157 File (java.io.File)151 DataInput (java.io.DataInput)112 InputStream (java.io.InputStream)109 EOFException (java.io.EOFException)90 ArrayList (java.util.ArrayList)90 FileNotFoundException (java.io.FileNotFoundException)88 FileOutputStream (java.io.FileOutputStream)52 InputStreamReader (java.io.InputStreamReader)52 BufferedReader (java.io.BufferedReader)50 Socket (java.net.Socket)44 ByteBuffer (java.nio.ByteBuffer)40 HashMap (java.util.HashMap)38