@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
@Override public int decode(InputStream is) throws IOException { return decode(is, true); }
@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); }
unitPrice = new BerReal(); subCodeLength += unitPrice.decode(is, false); subCodeLength += berTag.decode(is); itemTotal = new BerReal(); subCodeLength += itemTotal.decode(is, false); subCodeLength += berTag.decode(is); unitPrice = new BerReal(); subCodeLength += unitPrice.decode(is, false); subCodeLength += berTag.decode(is); itemTotal = new BerReal(); subCodeLength += itemTotal.decode(is, false); subCodeLength += berTag.decode(is);
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 = encodeValue(reverseOS); codeLength += BerLength.encodeLength(reverseOS, codeLength); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@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); }
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 = encodeValue(reverseOS); codeLength += BerLength.encodeLength(reverseOS, codeLength); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@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); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
@Override public int decode(InputStream is) throws IOException { return decode(is, true); }
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 = encodeValue(reverseOS); codeLength += BerLength.encodeLength(reverseOS, codeLength); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@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); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
@Override public int decode(InputStream is) throws IOException { return decode(is, true); }
@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); }
public void encodeAndSave(int encodingSizeGuess) throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess); encode(os, false); code = os.getArray(); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; if (withTag) { codeLength += tag.decodeAndCheck(is); } codeLength += super.decode(is, false); return codeLength; }
@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); }
public void encodeAndSave(int encodingSizeGuess) throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess); encode(os, false); code = os.getArray(); }