Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.*;

public class Main {
    /**
     * Converts a DER-encoded Oid from an InputStream to a dot-separated
     * String representation.
     *
     * @param oid DER-encoded Oid InputStream
     * @return Oid in dot-separated String representation
     *
     */
    public static byte[] OidStream2DER(InputStream oid) throws IOException {

        int tag;
        int length;
        ByteArrayOutputStream outOid = new ByteArrayOutputStream();

        try {
            tag = oid.read();
            length = oid.read();
            outOid.write(tag);
            outOid.write(length);

            for (int i = 0; i < length; i++) {
                outOid.write(oid.read());
            }
        } catch (IOException e) {
            throw new IOException("I/O Error occurred when reading InputStream");
        }

        return outOid.toByteArray();
    }
}