@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
public void encodeAndSave(int encodingSizeGuess) throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess); encode(os, false); code = os.getArray(); }
public void encodeAndSave(int encodingSizeGuess) throws IOException { BerByteArrayOutputStream berOStream = new BerByteArrayOutputStream(encodingSizeGuess); encode(berOStream, false); code = berOStream.getArray(); } }
public void encodeAndSave(int encodingSizeGuess) throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess); encode(os, false); code = os.getArray(); }
public void encodeAndSave(int encodingSizeGuess) throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess); encode(os, false); code = os.getArray(); }
public int encode(OutputStream reverseOS, boolean withTag) throws IOException { if (code != null) { for (int i = code.length - 1; i >= 0; i--) { reverseOS.write(code[i]); } if (withTag) { return tag.encode(reverseOS) + code.length; } return code.length; } int codeLength; codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Test public void coding0dot2() throws IOException { final BerReal orig = new BerReal(0.2); final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true); orig.encode(baos, true); final BerReal decoded = new BerReal(); decoded.decode(new ByteArrayInputStream(baos.getArray()), true); Assert.assertEquals(orig.value, decoded.value, 0.001); }
@Test public void coding1dot0() throws IOException { final BerReal orig = new BerReal(1.0); final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true); orig.encode(baos, true); final BerReal decoded = new BerReal(); decoded.decode(new ByteArrayInputStream(baos.getArray()), true); Assert.assertEquals(orig.value, decoded.value, 0.001); }
@Test public void coding2dot0() throws IOException { final BerReal orig = new BerReal(2.0); final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true); orig.encode(baos, true); final BerReal decoded = new BerReal(); decoded.decode(new ByteArrayInputStream(baos.getArray()), true); Assert.assertEquals(orig.value, decoded.value, 0.001); }
@Test public void codingNegInf() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerReal berReal = new BerReal(Double.NEGATIVE_INFINITY); berReal.encode(berStream, true); Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090141"), berStream.getArray()); ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray()); BerReal berRealDecoded = new BerReal(); berRealDecoded.decode(berInputStream, true); Assert.assertEquals(Double.NEGATIVE_INFINITY, berRealDecoded.value, 0.01); }
@Test public void coding1dot5() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerReal berReal = new BerReal(1.5); berReal.encode(berStream, true); // System.out.println(DatatypeConverter.printHexBinary(berStream.getArray())); Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090380FF03"), berStream.getArray()); ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray()); BerReal berRealDecoded = new BerReal(); berRealDecoded.decode(berInputStream, true); Assert.assertEquals(1.5, berRealDecoded.value, 0.01); }
@Test public void codingZero() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerReal berReal = new BerReal(0); berReal.encode(berStream, true); Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("0900"), berStream.getArray()); ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray()); BerReal berRealDecoded = new BerReal(); berRealDecoded.decode(berInputStream, true); Assert.assertEquals(0, berRealDecoded.value, 0.01); }
@Test public void coding0dot7() throws IOException { final BerReal orig = new BerReal(0.7); final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true); orig.encode(baos, true); // System.out.println(DatatypeConverter.printHexBinary(baos.getArray())); Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090980CC0B333333333333"), baos.getArray()); final BerReal decoded = new BerReal(); decoded.decode(new ByteArrayInputStream(baos.getArray()), true); Assert.assertEquals(orig.value, decoded.value, 0.001); }
codeLength += real.encode(reverseOS, true);