mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
4dbd404f64
* Remove non-deterministic classes from Avian (wip). * Complete integration between Avian and our local OpenJDK fork. * Revert accidental Avian modification. * Implements a "blacklist filter" for Avian's system classloader. * Remove .DSA, .RSA, .SF and .MF files when creating a fat jar. * Revert more accidental Avian changes. * Fix breakage with dependencies, and retain Kryo instance. * Apply blacklisting per thread rather than globally. * Blacklist java.lang.ClassLoader and all java.lang.Thread* classes. * Add comment explaining class blacklisting. * Fix Avian when building without OpenJDK. * Configure ProGuard to keep more classes for deserialisation. * Retain explicit return type for secure random function. * Add sources of random numbers to the class blacklist. * Blacklist the threading classes more precisely. * Make SystemClassLoader.isForbidden() static. * Prevent ProGuard from removing SerializedLambda.readResolve(). * Remove Avian tests involving direct buffers.
71 lines
2.0 KiB
Java
71 lines
2.0 KiB
Java
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.BufferedInputStream;
|
|
|
|
/**
|
|
* Checks that BufferedInputStream does not block if data is available in it's internal buffer.
|
|
*/
|
|
public class BufferedInputStreamTest
|
|
{
|
|
public static void main(String[] args) throws IOException
|
|
{
|
|
MyByteArrayStream in = new MyByteArrayStream(new byte[100]);
|
|
|
|
BufferedInputStream bin = new BufferedInputStream(in);
|
|
//read a single byte to fill the buffer
|
|
int b = bin.read();
|
|
byte[] buf = new byte[10];
|
|
//now try to read 10 bytes. this should a least return the content of the buffer. On OpenJDK this are
|
|
//4 bytes (the rest of the buffer returned by MyByteArrayStream in the first call).
|
|
//It should definately NOT block.
|
|
int count = bin.read(buf);
|
|
System.out.println("Read bytes: " + count);
|
|
}
|
|
|
|
/**
|
|
* Internal Stream used to show the BufferedInputStream behaviour.
|
|
*/
|
|
static class MyByteArrayStream extends ByteArrayInputStream
|
|
{
|
|
boolean stopReading = false;
|
|
|
|
/**
|
|
* @param buf
|
|
*/
|
|
public MyByteArrayStream(byte[] buf)
|
|
{
|
|
super(buf);
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see java.io.ByteArrayInputStream#read(byte[], int, int)
|
|
*/
|
|
@Override
|
|
public synchronized int read(byte[] b, int off, int len)
|
|
{
|
|
if(stopReading == false)
|
|
{ //On the first call 5 bytes are returned.
|
|
stopReading = true;
|
|
return super.read(b, off, 5);
|
|
}
|
|
//on all following calls block. The spec says, that a least one byte is returned, if the
|
|
//stream is not at EOF.
|
|
return 0;
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see java.io.ByteArrayInputStream#available()
|
|
*/
|
|
@Override
|
|
public synchronized int available()
|
|
{
|
|
if(stopReading)
|
|
{
|
|
return 0;
|
|
}
|
|
return super.available();
|
|
}
|
|
}
|
|
}
|