FileDocCategorySizeDatePackage
RandomInputStream.javaAPI DocExample1186Fri Feb 03 14:27:04 GMT 2006com.elharo.io

RandomInputStream

public class RandomInputStream extends InputStream

Fields Summary
private Random
generator
private boolean
closed
Constructors Summary
Methods Summary
public intavailable()

    // Limited only by available memory and the size of an array.
    return Integer.MAX_VALUE;
  
private voidcheckOpen()

      if (closed) throw new IOException("Input stream closed");
  
public voidclose()

      this.closed = true;
  
public intread()


       
    checkOpen();
    int result = generator.nextInt() % 256;
    if (result < 0) result = -result;
    return result;
  
public intread(byte[] data, int offset, int length)

    checkOpen();
    byte[] temp = new byte[length];
    generator.nextBytes(temp);
    System.arraycopy(temp, 0, data, offset, length);
    return length;

  
public intread(byte[] data)

    checkOpen();
    generator.nextBytes(data);
    return data.length;

  
public longskip(long bytesToSkip)

    checkOpen();
    // It's all random so skipping has no effect.
    return bytesToSkip;