Package com.peterhi.obsolete

Examples of com.peterhi.obsolete.Stream


  }

  @Test
  public void pReadLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        stream.writeLong(nwi.getNumber().longValue());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        assertEquals(nwi.getNumber().longValue(), stream.readLong());
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here


  }
 
  @Test
  public void fReadLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readLong();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[7]);
      stream.readLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadUnsignedLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        stream.writeLong(nwi.getNumber().longValue());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        BigInteger mask = BigInteger.valueOf(2).pow(Long.SIZE).subtract(BigInteger.ONE);
        assertEquals(nwi.getNumber().and(mask), stream.readUnsignedLong());
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadUnsignedLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readUnsignedLong();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readUnsignedLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[7]);
      stream.readUnsignedLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadLong_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        stream.writeLong(nwi.getNumber().longValue(), nwi.getBits());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        if (nwi.isNormal()) {
          assertEquals(nwi.getNumber().longValue(), stream.readLong(nwi.getBits()));
        } else {
          BigInteger flow = BigInteger.valueOf(2).pow(nwi.getBits());
          BigInteger left = nwi.getNumber();
          BigInteger right = BigInteger.valueOf(stream.readLong(nwi.getBits()));
         
          if (nwi.isOverflow()) {
            left = left.subtract(flow);
          } else {
            left = left.add(flow);
          }
         
          assertEquals(left, right);
        }
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadLong_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readLong(1);
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readLong(2);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[7]);
      stream.readLong(64);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadUnsignedLong_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        stream.writeLong(nwi.getNumber().longValue(), nwi.getBits());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(Long.SIZE)) {
        BigInteger mask = BigInteger.valueOf(2).pow(nwi.getBits()).subtract(BigInteger.ONE);
        BigInteger left = nwi.getNumber();
        BigInteger right = stream.readUnsignedLong(nwi.getBits());
       
        left = left.and(mask);
       
        assertEquals(left, right);
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadUnsignedLong_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readUnsignedLong(1);
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readUnsignedLong(2);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(new byte[7]);
      stream.readUnsignedLong(64);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadVarLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      int max = (int )(Math.pow(2, RT.INT62) * Byte.SIZE - 2);
     
      for (NumWithInfo nwi : genNumWithInfos(max)) {
        if (nwi.getBits() < max) {
          if (nwi.isOverflow() || nwi.isUnderflow()) {
            continue;
          }
        }
       
        stream.writeVarLong(nwi.getNumber().longValue());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(max)) {
        if (nwi.getBits() < max) {
          if (nwi.isOverflow() || nwi.isUnderflow()) {
            continue;
          }
        }
       
        if (nwi.isNormal()) {
          assertEquals(nwi.getNumber().longValue(), stream.readVarLong());
        } else {
          BigInteger flow = BigInteger.valueOf(2).pow(nwi.getBits());
          BigInteger left = nwi.getNumber();
          BigInteger right = BigInteger.valueOf(stream.readVarLong());
         
          if (nwi.isOverflow()) {
            left = left.subtract(flow);
          } else {
            left = left.add(flow);
          }
         
          assertEquals(left, right);
        }
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadVarLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readVarLong();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(2);
      stream.readVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.writeBit(1);
      stream.write(1);
      stream.readVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } 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.