use of java.io.PipedInputStream in project j2objc by google.
the class OldPipedOutputStreamTest method test_write$BII.
public void test_write$BII() throws IOException {
out = new PipedOutputStream();
try {
out.write(testString.getBytes(), 0, 5);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
out = new PipedOutputStream(new PipedInputStream());
try {
out.write(testString.getBytes(), -1, 10);
fail("Test 2: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
out.write(testString.getBytes(), 0, -1);
fail("Test 3: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
try {
out.write(testString.getBytes(), 5, testString.length());
fail("Test 4: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected.
}
out.close();
out = new PipedOutputStream();
try {
rt = new Thread(reader = new PReader(out));
rt.start();
out.write(testString.getBytes(), 0, testString.length());
out.flush();
assertEquals("Test 5: Bytes read do not match the bytes written. ", testString, reader.read(testString.length()));
} catch (IOException e) {
fail("Test 5: Unexpected IOException: " + e.getMessage());
}
reader.getReader().close();
try {
out.write(testString.getBytes(), 0, 5);
fail("Test 7: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.PipedInputStream in project j2objc by google.
the class OldPipedOutputStreamTest method test_ConstructorLjava_io_PipedInputStream.
public void test_ConstructorLjava_io_PipedInputStream() throws IOException {
try {
out = new PipedOutputStream(new PipedInputStream());
out.write('b');
} catch (Exception e) {
fail("Test 1: Constructor failed: " + e.getMessage());
}
out.close();
PipedInputStream pis = new PipedInputStream(new PipedOutputStream());
try {
out = new PipedOutputStream(pis);
fail("Test 2: IOException expected because the input stream is already connected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.PipedInputStream in project j2objc by google.
the class OldAndroidPipedStreamTest method testB.
public void testB() throws Exception {
final PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
assertEquals(0, in.available());
TestThread reader, writer;
reader = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
byte[] readBytes = new byte[5];
int ret;
for (; ; ) {
int nread = 0;
while (nread < 5) {
ret = in.read(readBytes, nread, readBytes.length - nread);
if (ret == -1) {
return;
}
nread += ret;
}
assertEquals(5, nread);
int readInt = (((int) readBytes[0] & 0xff) << 24) | (((int) readBytes[1] & 0xff) << 16) | (((int) readBytes[2] & 0xff) << 8) | (((int) readBytes[3] & 0xff));
assertEquals("Error at " + countRead, fib.next(), readInt);
assertEquals("Error at " + countRead, 0, readBytes[4]);
countRead++;
}
}
};
reader.start();
writer = new TestThread() {
Fibonacci fib = new Fibonacci();
@Override
public void runTest() throws Exception {
byte[] writeBytes = new byte[5];
for (int i = 0; i < 2000; i++) {
int toWrite = fib.next();
writeBytes[0] = (byte) (toWrite >> 24);
writeBytes[1] = (byte) (toWrite >> 16);
writeBytes[2] = (byte) (toWrite >> 8);
writeBytes[3] = (byte) (toWrite);
writeBytes[4] = 0;
out.write(writeBytes, 0, writeBytes.length);
}
out.close();
}
};
writer.start();
for (; ; ) {
try {
reader.join(60 * 1000);
writer.join(1000);
break;
} catch (InterruptedException ex) {
}
}
if (reader.exception != null) {
throw new Exception(reader.exception);
}
if (writer.exception != null) {
throw new Exception(writer.exception);
}
assertEquals(2000, reader.countRead);
}
use of java.io.PipedInputStream in project j2objc by google.
the class InputStreamReaderTest method testReadDoesNotBlockUnnecessarily.
/**
* This bug claims that InputStreamReader blocks unnecessarily:
* http://code.google.com/p/android/issues/detail?id=10252
*/
public void testReadDoesNotBlockUnnecessarily() throws IOException {
PipedInputStream pin = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pin);
pos.write("hello".getBytes("UTF-8"));
InputStreamReader reader = new InputStreamReader(pin);
char[] buffer = new char[1024];
int count = reader.read(buffer);
assertEquals(5, count);
}
use of java.io.PipedInputStream in project j2objc by google.
the class InterruptedStreamTest method testInterruptPipedOutputStream.
public void testInterruptPipedOutputStream() throws Exception {
PipedOutputStream out = new PipedOutputStream();
new PipedInputStream(out);
testInterruptOutputStream(out);
}
Aggregations