use of java.io.DataInputStream in project XobotOS by xamarin.
the class BluetoothService method readIncomingConnectionState.
private void readIncomingConnectionState() {
synchronized (mIncomingConnections) {
FileInputStream fstream = null;
try {
fstream = new FileInputStream(INCOMING_CONNECTION_FILE);
DataInputStream in = new DataInputStream(fstream);
BufferedReader file = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = file.readLine()) != null) {
line = line.trim();
if (line.length() == 0)
continue;
String[] value = line.split(",");
if (value != null && value.length == 3) {
Integer val1 = Integer.parseInt(value[1]);
Pair<Integer, String> val = new Pair(val1, value[2]);
mIncomingConnections.put(value[0], val);
}
}
} catch (FileNotFoundException e) {
log("FileNotFoundException: readIncomingConnectionState" + e.toString());
} catch (IOException e) {
log("IOException: readIncomingConnectionState" + e.toString());
} finally {
if (fstream != null) {
try {
fstream.close();
} catch (IOException e) {
// Ignore
}
}
}
}
}
use of java.io.DataInputStream in project hazelcast by hazelcast.
the class IOUtilTest method testNewInputStream_shouldThrowWhenByteBufferExhaustedAndTryingToReadFully.
@Test(expected = EOFException.class)
public void testNewInputStream_shouldThrowWhenByteBufferExhaustedAndTryingToReadFully() throws Exception {
ByteBuffer buffer = ByteBuffer.wrap(new byte[SIZE]);
DataInputStream inputStream = new DataInputStream(newInputStream(buffer));
inputStream.readFully(new byte[SIZE]);
inputStream.readFully(NON_EMPTY_BYTE_ARRAY);
}
use of java.io.DataInputStream in project hazelcast by hazelcast.
the class IOUtilTest method testNewInputStream_shouldThrowWhenTryingToReadFullyFromEmptyByteBuffer.
@Test(expected = EOFException.class)
public void testNewInputStream_shouldThrowWhenTryingToReadFullyFromEmptyByteBuffer() throws Exception {
ByteBuffer empty = ByteBuffer.wrap(EMPTY_BYTE_ARRAY);
DataInputStream inputStream = new DataInputStream(newInputStream(empty));
inputStream.readFully(NON_EMPTY_BYTE_ARRAY);
}
use of java.io.DataInputStream in project guava by hceylan.
the class LittleEndianDataOutputStreamTest method testWriteBytes_discardHighOrderBytes.
// testing a deprecated method
@SuppressWarnings("deprecation")
public void testWriteBytes_discardHighOrderBytes() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.writeBytes("ꪪꪻ");
byte[] data = baos.toByteArray();
/* Setup input streams */
DataInput in = new DataInputStream(new ByteArrayInputStream(data));
/* Read in various values NORMALLY */
byte[] b = new byte[3];
in.readFully(b);
byte[] expected = { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC };
assertEquals(expected, b);
}
use of java.io.DataInputStream in project guava by hceylan.
the class LittleEndianDataOutputStreamTest method testWriteLittleEndian.
public void testWriteLittleEndian() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.write(new byte[] { -100, 100 });
out.writeBoolean(true);
out.writeBoolean(false);
out.writeByte(100);
out.writeByte(-100);
out.writeByte((byte) 200);
out.writeChar('a');
out.writeShort((short) -30000);
out.writeShort((short) 50000);
out.writeInt(0xCAFEBABE);
out.writeLong(0xDEADBEEFCAFEBABEL);
out.writeUTF("Herby Derby");
out.writeFloat(Float.intBitsToFloat(0xCAFEBABE));
out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL));
byte[] data = baos.toByteArray();
/* Setup input streams */
DataInput in = new DataInputStream(new ByteArrayInputStream(data));
/* Read in various values NORMALLY */
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertEquals(true, in.readBoolean());
assertEquals(false, in.readBoolean());
assertEquals(100, in.readByte());
assertEquals(-100, in.readByte());
assertEquals(200, in.readUnsignedByte());
assertEquals('愀', in.readChar());
assertEquals(-12150, in.readShort());
assertEquals(20675, in.readUnsignedShort());
assertEquals(0xBEBAFECA, in.readInt());
assertEquals(0xBEBAFECAEFBEADDEL, in.readLong());
assertEquals("Herby Derby", in.readUTF());
assertEquals(0xBEBAFECA, Float.floatToIntBits(in.readFloat()));
assertEquals(0xBEBAFECAEFBEADDEL, Double.doubleToLongBits(in.readDouble()));
}
Aggregations