Package com.peterhi.obsolete

Examples of com.peterhi.obsolete.Stream


 
  @Test
  public void pMark_int() throws Exception {
    try {
      int whatever = 672695543;
      Stream stream = new Stream(sampleBytes());
      assertEquals(sampleBytes()[0], (byte )stream.read());
      stream.mark(whatever);
      assertEquals(sampleBytes()[1], (byte )stream.read());
      assertEquals(sampleBytes()[2], (byte )stream.read());
      stream.reset();
      assertEquals(sampleBytes()[1], (byte )stream.read());
      assertEquals(7, stream.available());
    } finally {
    }
  }
View Full Code Here


 
  @Test
  public void pReset_void() throws Exception {
    try {
      int whatever = 546543324;
      Stream stream = new Stream(sampleBytes());
      assertEquals(sampleBytes()[0], (byte )stream.read());
      stream.reset();
      assertEquals(sampleBytes()[1], (byte )stream.read());
      stream.mark(whatever);
      assertEquals(sampleBytes()[2], (byte )stream.read());
      stream.reset();
      assertEquals(sampleBytes()[2], (byte )stream.read());
      assertEquals(6, stream.available());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pMarkSupported_void() throws Exception {
    try {
      Stream stream = new Stream();
      assertEquals(true, stream.markSupported());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pWriteBit_int() throws Exception {
    try {
      Stream stream = new Stream();
     
      for (int i = 0; i < 9; i++) {
        stream.writeBit(i % 2);
      }
     
      stream.writeBit(43553455);
     
      for (int i = 0; i < 9; i++) {
        assertEquals(i % 2, stream.readBit());
      }
     
      assertEquals(1, stream.readBit());
      assertEquals(-1, stream.readBit());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pWriteBit2_boolean() throws Exception {
    try {
      Stream stream = new Stream();
     
      for (int i = 0; i < 9; i++) {
        stream.writeBit2(i % 2 == 0);
      }
     
      for (int i = 0; i < 9; i++) {
        assertEquals(i % 2 == 0, stream.readBit2());
      }
     
      assertEquals(-1, stream.readBit());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pWrite_byteArray() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.write(sampleBytes());
      stream.writeBit(1);
      stream.readBit();

      for (int i = 0; i < sampleBytes().length; i++) {
        assertEquals(sampleBytes()[i], (byte )stream.read());
      }
     
      assertEquals(1, stream.getData().readable());
     
      byte[] sample = new byte[0];
      stream.write(sample);
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fWrite_byteArray() throws Exception {
    try {
      Stream stream = new Stream();
      stream.write(null);
      fail();
    } catch (NullPointerException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pWrite_byteArray_int_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.write(sampleBytes(), 0, 1);
      stream.writeBit(1);
      stream.write(sampleBytes(), 1, 0);
      stream.write(sampleBytes(), 1, sampleBytes().length - 1);
      stream.writeBit(1);
      stream.readBit();
     
      assertEquals(sampleBytes()[0], (byte )stream.read());
      stream.readBit();
     
      for (int i = 0; i < sampleBytes().length - 1; i++) {
        assertEquals(sampleBytes()[i + 1], (byte )stream.read());
      }
     
      assertEquals(1, stream.getData().readable());
      byte[] sample = new byte[0];
      stream.write(sample, 0, 0);
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fWrite_byteArray_int_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.write(null, 0, 0);
      fail();
    } catch (NullPointerException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[0], -1, 0);
      fail();
    } catch (IllegalArgumentException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[0], 0, -1);
      fail();
    } catch (IllegalArgumentException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[0], 0, 1);
      fail();
    } catch (IndexOutOfBoundsException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadFully_byteArray() throws Exception {
    try {
      Stream stream = new Stream(sampleBytes());
      byte[] sample = new byte[0];
     
      stream.readFully(sample);
      assertEquals(sampleBytes().length, stream.available());
     
      sample = new byte[2];
      stream.readFully(sample);
     
      for (int i = 0; i < sample.length; i++) {
        assertEquals(sampleBytes()[i], sample[i]);
      }
     
      sample = new byte[7];
      stream.readFully(sample);
     
      for (int i = 0; i < sample.length; i++) {
        assertEquals(sampleBytes()[i + 2], sample[i]);
      }
     
      assertEquals(0, stream.available());
      sample = new byte[0];
      stream.readFully(sample);
      assertEquals(0, stream.available());
    } finally {
    }
  }
View Full Code Here

TOP

Related Classes of com.peterhi.obsolete.Stream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.