Package com.peterhi.obsolete

Examples of com.peterhi.obsolete.Stream


  }
 
  @Test
  public void fReadDouble_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readDouble();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readDouble();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.readDouble();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here


  }
 
  @Test
  public void pReadBigDecimal_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      List<BigDecimal> numbers = new ArrayList<BigDecimal>();
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        BigInteger unscaled = nwi.getNumber();
        int scale = new Random(System.currentTimeMillis()).nextInt(0xffff);
        numbers.add(new BigDecimal(unscaled, scale));
      }
     
      for (BigDecimal number : numbers) {
        stream.writeBigDecimal(number);
      }
     
      stream.writeBit(1);
     
      stream.readBit();

      for (BigDecimal number : numbers) {
        assertEquals(number, stream.readBigDecimal());
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadBigDecimal_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readBigDecimal();
      fail();
    } catch (EOFException ex) {
    }

    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readBigDecimal();
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.readBigDecimal();
      fail();
    } catch (InsufficientBufferException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadBigDecimal_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      List<BigDecimal> numbers = new ArrayList<BigDecimal>();
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        BigInteger unscaled = nwi.getNumber();
        int scale = new Random(System.currentTimeMillis()).nextInt(0xffff);
        numbers.add(new BigDecimal(unscaled, scale));
      }
     
      for (BigDecimal number : numbers) {
        stream.writeBigDecimal(number, number.unscaledValue().bitLength() + 1);
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (BigDecimal number : numbers) {
        assertEquals(number, stream.readBigDecimal(number.unscaledValue().bitLength() + 1));
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadBigDecimal_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readBigDecimal(1);
      fail();
    } catch (EOFException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readBigDecimal(1);
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.writeBit(1);
      stream.writeBit(1);
      stream.readBigDecimal(1);
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(1);
      stream.readBigDecimal(0);
      fail();
    } catch (InsufficientBufferException ex) {
    }
  }
View Full Code Here

  @Test
  public void pReadLine_void() throws Exception {
    try {
      String template = "Hello World!";
      String text = "Hello World!\nHello World!\rHello World!\n\rHello World!\nHello World!\n";
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.write(text.getBytes(Charset.forName("ascii")));
      stream.writeBit(1);
     
      stream.readBit();
     
      for (int i = 0; i < 5; i++) {
        assertEquals(template, stream.readLine());
      }
     
      assertEquals("", stream.readLine());
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadInt_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(Integer.SIZE)) {
        stream.writeInt(nwi.getNumber().intValue(), nwi.getBits());
      }
     
      stream.writeBit(1);
     
      stream.readBit();

      for (NumWithInfo nwi : genNumWithInfos(Integer.SIZE)) {
        if (nwi.isNormal()) {
          assertEquals(nwi.getNumber().intValue(), stream.readInt(nwi.getBits()));
        } else {
          BigInteger flow = BigInteger.valueOf(2).pow(nwi.getBits());
          BigInteger left = nwi.getNumber();
          BigInteger right = BigInteger.valueOf(stream.readInt(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 fReadInt_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readInt(1);
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readInt(2);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.readInt(32);
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

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

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