ASN1InputStream ais = new ASN1InputStream( new FileInputStream(new File("d:/myfile.cdr"))); while (ais.available() > 0) { ASN1Primitive obj = ais.readObject(); System.out.println(ASN1Dump.dumpAsString(obj, true)); } ais.close();
/** * Create a base ASN.1 object from a byte stream. * * @param data the byte stream to parse. * @return the base ASN.1 object represented by the byte stream. * @exception IOException if there is a problem parsing the data, or parsing the stream did not exhaust the available data. */ public static ASN1Primitive fromByteArray(byte[] data) throws IOException { ASN1InputStream aIn = new ASN1InputStream(data); try { ASN1Primitive o = aIn.readObject(); if (aIn.available() != 0) { throw new IOException("Extra data detected in stream"); } return o; } catch (ClassCastException e) { throw new IOException("cannot recognise object in stream"); } }
if (ais.available() > 0 ) { ASN1Object d = ais.readObject(); String txt = ASN1Dump.dumpAsString(d, true);
@Override public boolean hasNext() { try { if (asn1InputStream == null) { return false; } boolean availableDataInCurrentEntry = asn1InputStream.available() > 0; if (!availableDataInCurrentEntry) { // advance to the next entry. parent = getNextElement(); if (parent == null) { asn1InputStream.close(); availableDataInCurrentEntry = false; } else { availableDataInCurrentEntry = true; } } return availableDataInCurrentEntry; } catch (IOException exception) { // Just wrap the IOException as CamelRuntimeException throw new RuntimeCamelException(exception); } }
@Override public boolean hasNext() { try { if (asn1InputStream == null) { return false; } boolean availableDataInCurrentEntry = asn1InputStream.available() > 0; if (!availableDataInCurrentEntry) { // advance to the next entry. parent = getNextElement(); if (parent == null) { asn1InputStream.close(); availableDataInCurrentEntry = false; } else { availableDataInCurrentEntry = true; } } return availableDataInCurrentEntry; } catch (IOException exception) { //Just wrap the IOException as CamelRuntimeException throw new RuntimeCamelException(exception); } }
if (ais.available() > 0 ) { ASN1Object d = ais.readObject(); String txt = ASN1Dump.dumpAsString(d, true);
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { if (usingIterator) { if (clazzName != null) { Class<?> clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(clazzName); ASN1GenericIterator asn1GenericIterator = new ASN1GenericIterator(clazz, stream); return asn1GenericIterator; } ASN1MessageIterator asn1MessageIterator = new ASN1MessageIterator(exchange, stream); return asn1MessageIterator; } else { ASN1Primitive asn1Record = null; byte[] asn1Bytes; try (ASN1InputStream ais = new ASN1InputStream(stream); ByteArrayOutputStream asn1Out = new ByteArrayOutputStream();) { while (ais.available() > 0) { asn1Record = ais.readObject(); asn1Out.write(asn1Record.getEncoded()); } asn1Bytes = asn1Out.toByteArray(); } return asn1Bytes; } }