/*
 * Created by brightSPARK Labs
 * www.brightsparklabs.com
 */

package com.brightsparklabs.asanti.logic;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.logging.Logger;

import com.brightsparklabs.asanti.model.data.AsnData;
import com.brightsparklabs.asanti.reader.AsnBerFileReader;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.common.io.BaseEncoding;

/**
 * Logic for decoding tagged/application ASN.1 data
 *
 * @author brightSPARK Labs
 */
public class AsnDecoder
{
    // -------------------------------------------------------------------------
    // CLASS VARIABLES
    // -------------------------------------------------------------------------

    /** class logger */
    private static Logger log = Logger.getLogger(AsnDecoder.class.getName());

    // -------------------------------------------------------------------------
    // PUBLIC METHODS
    // -------------------------------------------------------------------------

    /**
     * Main method. Used for testing.
     *
     * @param args
     *            command line arguments
     */
    public static void main(String[] args)
    {
        try
        {
            final String filename = args[0];
            final File asnFile = new File(filename);

            //new AsnSchemaDefault(asnFile);
            final ImmutableList<AsnData> data = readAsnBerFile(asnFile);
            int count = 0;
            for (AsnData asnData : data)
            {
                log.info("PDU[" + count + "]");
                final Map<String, byte[]> tagsData = asnData.getBytes();

                for (String tag : Ordering.natural().immutableSortedCopy(tagsData.keySet()))
                {
                    log.info("\t" + tag + ": 0x" + BaseEncoding.base16().encode(tagsData.get(tag)));
                }
                count++;
            }
        }
        catch (Exception ex)
        {
            log.severe("Could not parser file - " + ex.getMessage());
        }
    }

    /**
     * Reads the supplied ASN.1 BER/DER binary file
     *
     * @param berFile
     *            file to decode
     *
     * @return list of {@link AsnData} objects found in the file
     *
     * @throws IOException
     *             if any errors occur reading from the file
     */
    public static ImmutableList<AsnData> readAsnBerFile(File berFile) throws IOException
    {
        return AsnBerFileReader.read(berFile);
    }
}

@@ -320,16 +320,78 @@
 Reader;%0A
+import com.brightsparklabs.asanti.reader.AsnSchemaFileReader;%0A
 import c
@@ -1414,41 +1414,153 @@
     
-//new AsnSchemaDefault(asnFile);%0A
+if (filename.endsWith(%22.asn%22))%0A            %7B%0A                AsnSchemaFileReader.read(asnFile);%0A            %7D%0A            else%0A            %7B%0A    
     
@@ -1640,16 +1640,20 @@
         
+ 
+   
 int coun
@@ -1659,16 +1659,20 @@
 nt = 0;%0A
+    
         
@@ -1704,16 +1704,20 @@
 : data)%0A
+    
         
@@ -1730,32 +1730,36 @@
                 
+    
 log.info(%22PDU%5B%22 
@@ -1774,16 +1774,20 @@
 + %22%5D%22);%0A
+    
         
@@ -1848,24 +1848,28 @@
 etBytes();%0A%0A
+    
             
@@ -1957,34 +1957,42 @@
                 
-%7B%0A
+    %7B%0A    
                 
@@ -2084,34 +2084,42 @@
                 
+   
+ 
 %7D%0A
+    
                 
@@ -2127,16 +2127,34 @@
 ount++;%0A
+                %7D%0A
         

Update main class to support testing of AsnSchemaFileReader