@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 int encode(OutputStream os) throws IOException { if (code != null) { for (int i = code.length - 1; i >= 0; i--) { os.write(code[i]); } return code.length; } int codeLength = 0; if (basicObjectClass != null) { codeLength += basicObjectClass.encode(os, false); // write tag: CONTEXT_CLASS, PRIMITIVE, 0 os.write(0x80); codeLength += 1; return codeLength; } throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
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) throws IOException { if (code != null) { for (int i = code.length - 1; i >= 0; i--) { reverseOS.write(code[i]); } return code.length; } int codeLength = 0; if (test != null) { codeLength += test.encode(reverseOS, true); return codeLength; } throw new IOException("Error encoding CHOICE: No element of CHOICE was selected."); }
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; }
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; }
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; }
@Override public int encode(OutputStream os, boolean withTag) throws IOException { int codeLength = super.encode(os, false); if (withTag) { codeLength += BerLength.encodeLength(os, codeLength); codeLength += identifier.encode(os); } return codeLength; }
@Test public void encodeDecodeLargeLongs() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); BerInteger myInt = new BerInteger(BigInteger.valueOf(20093243433l)); myInt.encode(os, true); ByteArrayInputStream berInputStream = new ByteArrayInputStream(os.getArray()); BerInteger myInt2 = new BerInteger(); myInt2.decode(berInputStream, true); Assert.assertEquals(20093243433l, myInt2.value.longValue()); }
@Test public void encodeDecodeLargeNegativeLongs() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); BerInteger myInt = new BerInteger(BigInteger.valueOf(-20093243433l)); myInt.encode(berBAOStream, true); ByteArrayInputStream berInputStream = new ByteArrayInputStream(berBAOStream.getArray()); BerInteger myInt2 = new BerInteger(); myInt2.decode(berInputStream, true); Assert.assertEquals(-20093243433l, myInt2.value.longValue()); }
@Test public void explicitEncoding2() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerInteger testInteger = new BerInteger(BigInteger.valueOf(5555)); int length = testInteger.encode(berStream, true); Assert.assertEquals(4, length); byte[] expectedBytes = new byte[] { 0x02, 0x02, 0x15, (byte) 0xb3 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); // 51 is the example in X.690 BerInteger testInteger = new BerInteger(BigInteger.valueOf(51)); int length = testInteger.encode(berStream, true); Assert.assertEquals(3, length); byte[] expectedBytes = new byte[] { 0x02, 0x01, 0x33 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }