Example usage for java.lang Exception Exception

List of usage examples for java.lang Exception Exception

Introduction

In this page you can find the example usage for java.lang Exception Exception.

Prototype

public Exception(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:at.co.malli.relpm.RelPM.java

/**
 * @param args the command line arguments
 *///from ww  w .j av  a  2 s.  c o m
public static void main(String[] args) {
    //<editor-fold defaultstate="collapsed" desc=" Create config & log directory ">
    String userHome = System.getProperty("user.home");
    File relPm = new File(userHome + "/.RelPM");
    if (!relPm.exists()) {
        boolean worked = relPm.mkdir();
        if (!worked) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not create directory "
                    + relPm.getAbsolutePath() + " to store user-settings and logs"));
            System.exit(-1);
        }
    }
    File userConfig = new File(relPm.getAbsolutePath() + "/RelPM-userconfig.xml"); //should be created...
    if (!userConfig.exists()) {
        try {
            URL resource = RelPM.class.getResource("/at/co/malli/relpm/RelPM-defaults.xml");
            FileUtils.copyURLToFile(resource, userConfig);
        } catch (IOException ex) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not copy default config. Reason:\n"
                    + ex.getClass().getName() + ": " + ex.getMessage()));
            System.exit(-1);
        }
    }
    if (!userConfig.canWrite() || !userConfig.canRead()) {
        ExceptionDisplayer.showErrorMessage(new Exception(
                "Can not read or write " + userConfig.getAbsolutePath() + "to store user-settings"));
        System.exit(-1);
    }
    if (System.getProperty("os.name").toLowerCase().contains("win")) {
        Path relPmPath = Paths.get(relPm.toURI());
        try {
            Files.setAttribute(relPmPath, "dos:hidden", true);
        } catch (IOException ex) {
            ExceptionDisplayer.showErrorMessage(new Exception("Could not set " + relPm.getAbsolutePath()
                    + " hidden. " + "Reason:\n" + ex.getClass().getName() + ": " + ex.getMessage()));
            System.exit(-1);
        }
    }
    //</editor-fold>

    logger.trace("Environment setup sucessfull");

    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code ">
    try {
        String wantedLookAndFeel = SettingsProvider.getInstance().getString("gui.lookAndFeel");
        UIManager.LookAndFeelInfo[] installed = UIManager.getInstalledLookAndFeels();
        boolean found = false;
        for (UIManager.LookAndFeelInfo info : installed) {
            if (info.getClassName().equals(wantedLookAndFeel))
                found = true;
        }
        if (found)
            UIManager.setLookAndFeel(wantedLookAndFeel);
        else
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (InstantiationException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (IllegalAccessException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        logger.error(ex.getMessage());
        ExceptionDisplayer.showErrorMessage(ex);
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Add GUI start to awt EventQue ">
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainGUI().setVisible(true);
        }
    });
    //</editor-fold>
}

From source file:org.soasecurity.wso2.mutual.auth.oauth2.client.MutualSSLOAuthClient.java

public static void main(String[] args) throws Exception {

    File file = new File((new File(".")).getCanonicalPath() + File.separator + "src" + File.separator + "main"
            + File.separator + "resources" + File.separator + "keystore" + File.separator + keyStoreName);

    if (!file.exists()) {
        throw new Exception("Key Store file can not be found in " + file.getCanonicalPath());
    }// w ww .  j  a  va2 s. co m

    //Set trust store, you need to import server's certificate of CA certificate chain in to this
    //key store
    System.setProperty("javax.net.ssl.trustStore", file.getCanonicalPath());
    System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);

    //Set key store, this must contain the user private key
    //here we have use both trust store and key store as the same key store
    //But you can use a separate key store for key store an trust store.
    System.setProperty("javax.net.ssl.keyStore", file.getCanonicalPath());
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);

    HttpClient client = new HttpClient();

    HttpMethod method = new PostMethod(endPoint);

    // Base64 encoded client id & secret
    method.setRequestHeader("Authorization",
            "Basic T09pN2dpUjUwdDZtUmU1ZkpmWUhVelhVa1QwYTpOOUI2dDZxQ0E2RFp2eTJPQkFIWDhjVlI1eUlh");
    method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    NameValuePair pair1 = new NameValuePair();
    pair1.setName("grant_type");
    pair1.setValue("x509");

    NameValuePair pair2 = new NameValuePair();
    pair2.setName("username");
    pair2.setValue("asela");

    NameValuePair pair3 = new NameValuePair();
    pair3.setName("password");
    pair3.setValue("asela");

    method.setQueryString(new NameValuePair[] { pair1, pair2, pair3 });

    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {

        System.out.println("Failed: " + method.getStatusLine());

    } else {

        byte[] responseBody = method.getResponseBody();

        System.out.println(new String(responseBody));
    }
}

From source file:com.congiu.load.csv.Main.java

public static void main(String[] args) {
    Options opts = buildCommandLineOptions();

    Configuration conf = new Configuration();

    try {//from   w  w w. j a  v  a2 s .  c o  m
        CommandLine cmd = processArguments(opts, args);

        if (cmd.hasOption(OPT_HELP[0])) {
            printUsage(opts, new PrintWriter(System.out));
            System.exit(0);
        }

        // all unprocessed arguments are files.
        // let's first check if they all exist
        for (String s : cmd.getArgs()) {
            if (!FSUtils.fileExists(conf, s)) {
                throw new Exception("File " + s + " does not exist.");
            }
        }

        CSVConverter converter = getCSVConverter(cmd);

        for (String s : cmd.getArgs()) {

        }

    } catch (Exception ex) {
        System.err.println("There was a problem parsing your arguments.");
        System.err.println(ex);
        printUsage(opts, new PrintWriter(System.err));
        System.exit(-1);
    }
}

From source file:com.floragunn.searchguard.tools.Hasher.java

public static void main(final String[] args) {

    final Options options = new Options();
    final HelpFormatter formatter = new HelpFormatter();
    options.addOption(//from w  w  w.  j  a v  a2  s.co  m
            Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build());
    options.addOption(Option.builder("env").argName("name environment variable").hasArg()
            .desc("name environment variable to read password from").build());

    final CommandLineParser parser = new DefaultParser();
    try {
        final CommandLine line = parser.parse(options, args);

        if (line.hasOption("p")) {
            System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8")));
        } else if (line.hasOption("env")) {
            final String pwd = System.getenv(line.getOptionValue("env"));
            if (pwd == null || pwd.isEmpty()) {
                throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set");
            }
            System.out.println(hash(pwd.getBytes("UTF-8")));
        } else {
            final Console console = System.console();
            if (console == null) {
                throw new Exception("Cannot allocate a console");
            }
            final char[] passwd = console.readPassword("[%s]", "Password:");
            System.out.println(hash(new String(passwd).getBytes("UTF-8")));
        }
    } catch (final Exception exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        formatter.printHelp("hasher.sh", options, true);
        System.exit(-1);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.loader.CommandLineLoader.java

public static void main(final String[] args) {
    try {//from   w w w  .  j  a  va2 s  . co  m
        if (args.length != 1) {
            throw new Exception("Expected filename argument");
        }
        configureDataSource();
        configureDccCommonDataSource();
        List<FileListRecord> fileList = readFileList(args[0]);
        CommandLineLoader cll = new CommandLineLoader(fileList);
        cll.go();
    } catch (Exception e) { //catch everything including runtime exceptions
        logger.logToLogger(Level.ERROR, String.format("ERROR: %s", e.getMessage()));
    }
}

From source file:edu.toronto.cs.xcurator.cli.CLIRunner.java

public static void main(String[] args) {
    Options options = setupOptions();/*from  ww  w  .  j a v a2 s .co  m*/
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption('t')) {
            fileType = line.getOptionValue('t');
        } else {
            fileType = XML;
        }
        if (line.hasOption('o')) {
            tdbDirectory = line.getOptionValue('o');
            File d = new File(tdbDirectory);
            if (!d.exists() || !d.isDirectory()) {
                throw new Exception("TDB directory does not exist, please create.");
            }
        }
        if (line.hasOption('h')) {
            domain = line.getOptionValue('h');
            try {
                URL url = new URL(domain);
            } catch (MalformedURLException ex) {
                throw new Exception("The domain name is ill-formed");
            }
        } else {
            printHelpAndExit(options);
        }
        if (line.hasOption('m')) {
            serializeMapping = true;
            mappingFilename = line.getOptionValue('m');
        }
        if (line.hasOption('d')) {
            dirLocation = line.getOptionValue('d');
            inputStreams = new ArrayList<>();
            final List<String> files = Util.getFiles(dirLocation);
            for (String inputfile : files) {
                File f = new File(inputfile);
                if (f.isFile() && f.exists()) {
                    System.out.println("Adding document to mapping discoverer: " + inputfile);
                    inputStreams.add(new FileInputStream(f));
                } // If it is a URL download link for the document from SEC
                else if (inputfile.startsWith("http") && inputfile.contains("://")) {
                    // Download
                    System.out.println("Adding remote document to mapping discoverer: " + inputfile);
                    try {
                        URL url = new URL(inputfile);
                        InputStream remoteDocumentStream = url.openStream();
                        inputStreams.add(remoteDocumentStream);
                    } catch (MalformedURLException ex) {
                        throw new Exception("The document URL is ill-formed: " + inputfile);
                    } catch (IOException ex) {
                        throw new Exception("Error in downloading remote document: " + inputfile);
                    }
                } else {
                    throw new Exception("Cannot open XBRL document: " + f.getName());
                }
            }
        }

        if (line.hasOption('f')) {
            fileLocation = line.getOptionValue('f');
            inputStreams = new ArrayList<>();
            File f = new File(fileLocation);
            if (f.isFile() && f.exists()) {
                System.out.println("Adding document to mapping discoverer: " + fileLocation);
                inputStreams.add(new FileInputStream(f));
            } // If it is a URL download link for the document from SEC
            else if (fileLocation.startsWith("http") && fileLocation.contains("://")) {
                // Download
                System.out.println("Adding remote document to mapping discoverer: " + fileLocation);
                try {
                    URL url = new URL(fileLocation);
                    InputStream remoteDocumentStream = url.openStream();
                    inputStreams.add(remoteDocumentStream);
                } catch (MalformedURLException ex) {
                    throw new Exception("The document URL is ill-formed: " + fileLocation);
                } catch (IOException ex) {
                    throw new Exception("Error in downloading remote document: " + fileLocation);
                }
            } else {

                throw new Exception("Cannot open XBRL document: " + f.getName());
            }

        }

        setupDocumentBuilder();
        RdfFactory rdfFactory = new RdfFactory(new RunConfig(domain));
        List<Document> documents = new ArrayList<>();
        for (InputStream inputStream : inputStreams) {
            Document dataDocument = null;
            if (fileType.equals(JSON)) {
                String json = IOUtils.toString(inputStream);
                final String xml = Util.json2xml(json);
                final InputStream xmlInputStream = IOUtils.toInputStream(xml);
                dataDocument = createDocument(xmlInputStream);
            } else {
                dataDocument = createDocument(inputStream);
            }
            documents.add(dataDocument);
        }
        if (serializeMapping) {
            System.out.println("Mapping file will be saved to: " + new File(mappingFilename).getAbsolutePath());
            rdfFactory.createRdfs(documents, tdbDirectory, mappingFilename);
        } else {
            rdfFactory.createRdfs(documents, tdbDirectory);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("Unexpected exception: " + ex.getMessage());
        System.exit(1);
    }
}

From source file:mase.stat.MasterTournament.java

public static void main(String[] args) throws Exception {
    List<File> sampleFolders = new ArrayList<>();
    List<File> testFolders = new ArrayList<>();
    int freq = 0;
    String name = "";
    boolean self = false;
    String individuals = null;/*from w  w  w.j av  a2  s .c o  m*/
    int elite = 0;

    for (int x = 0; x < args.length; x++) {
        if (args[x].equalsIgnoreCase(TEST_FOLDER)) {
            File folder = new File(args[1 + x++]);
            if (!folder.exists()) {
                throw new Exception("Folder does not exist: " + folder.getAbsolutePath());
            }
            testFolders.add(folder);
        } else if (args[x].equalsIgnoreCase(SAMPLE_FOLDER)) {
            File folder = new File(args[1 + x++]);
            if (!folder.exists()) {
                throw new Exception("Folder does not exist: " + folder.getAbsolutePath());
            }
            sampleFolders.add(folder);
        } else if (args[x].equalsIgnoreCase(BOTH_FOLDER)) {
            File folder = new File(args[1 + x++]);
            if (!folder.exists()) {
                throw new Exception("Folder does not exist: " + folder.getAbsolutePath());
            }
            sampleFolders.add(folder);
            testFolders.add(folder);
        } else if (args[x].equalsIgnoreCase(FREQUENCY)) {
            freq = Integer.parseInt(args[1 + x++]);
        } else if (args[x].equalsIgnoreCase(ELITE)) {
            elite = Integer.parseInt(args[1 + x++]);
        } else if (args[x].equalsIgnoreCase(OUTNAME)) {
            name = args[1 + x++];
        } else if (args[x].equalsIgnoreCase(SELF)) {
            self = true;
        } else if (args[x].equalsIgnoreCase(INDIVIDUALS)) {
            individuals = args[1 + x++];
        }
    }

    if (testFolders.isEmpty() || sampleFolders.isEmpty()) {
        System.out.println("Nothing to evaluate!");
        return;
    }

    MaseProblem sim = Reevaluate.createSimulator(args);
    MasterTournament mt = new MasterTournament(sampleFolders, testFolders, sim, name);

    if (individuals != null) {
        mt.makeIndsTournaments(individuals);
    } else if (self) {
        mt.makeSelfTournaments(freq);
    } else {
        mt.makeSampleTournaments(freq, elite);
    }

    mt.executor.shutdown();
}

From source file:edu.msu.cme.rdp.graph.sandbox.KmerStartsFromKnown.java

public static void main(String[] args) throws Exception {
    final KmerStartsWriter out;
    final boolean translQuery;
    final int wordSize;
    final int translTable;

    try {/*from   w  w w.j  a v  a2  s .c  o  m*/
        CommandLine cmdLine = new PosixParser().parse(options, args);
        args = cmdLine.getArgs();

        if (args.length < 2) {
            throw new Exception("Unexpected number of arguments");
        }

        if (cmdLine.hasOption("out")) {
            out = new KmerStartsWriter(cmdLine.getOptionValue("out"));
        } else {
            out = new KmerStartsWriter(System.out);
        }

        if (cmdLine.hasOption("transl-table")) {
            translTable = Integer.valueOf(cmdLine.getOptionValue("transl-table"));
        } else {
            translTable = 11;
        }

        translQuery = cmdLine.hasOption("transl-kmer");
        wordSize = Integer.valueOf(args[0]);

    } catch (Exception e) {
        new HelpFormatter().printHelp("KmerStartsFromKnown <word_size> [name=]<ref_file> ...", options);
        System.err.println(e.getMessage());
        System.exit(1);
        throw new RuntimeException("Stupid jvm"); //While this will never get thrown it is required to make sure javac doesn't get confused about uninitialized variables
    }

    long startTime = System.currentTimeMillis();

    /*
     * if (args.length == 4) { maxThreads = Integer.valueOf(args[3]); } else
     * {
     */

    //}

    System.err.println("Starting kmer mapping at " + new Date());
    System.err.println("*  References:              " + Arrays.asList(args));
    System.err.println("*  Kmer length:             " + wordSize);

    for (int index = 1; index < args.length; index++) {
        String refName;
        String refFileName = args[index];
        if (refFileName.contains("=")) {
            String[] lexemes = refFileName.split("=");
            refName = lexemes[0];
            refFileName = lexemes[1];
        } else {
            String tmpName = new File(refFileName).getName();
            if (tmpName.contains(".")) {
                refName = tmpName.substring(0, tmpName.lastIndexOf("."));
            } else {
                refName = tmpName;
            }
        }

        File refFile = new File(refFileName);

        if (SeqUtils.guessSequenceType(refFile) != SequenceType.Nucleotide) {
            throw new Exception("Reference file " + refFile + " contains " + SeqUtils.guessFileFormat(refFile)
                    + " sequences but expected nucleotide sequences");
        }

        SequenceReader seqReader = new SequenceReader(refFile);
        Sequence seq;

        while ((seq = seqReader.readNextSequence()) != null) {
            if (seq.getSeqName().startsWith("#")) {
                continue;
            }
            ModelPositionKmerGenerator kmers = new ModelPositionKmerGenerator(seq.getSeqString(), wordSize,
                    SequenceType.Nucleotide);

            for (char[] charmer : kmers) {
                int pos = kmers.getModelPosition() - 1;
                if (translQuery) {
                    if (pos % 3 != 0) {
                        continue;
                    } else {
                        pos /= 3;
                    }
                }

                String kmer = new String(charmer);

                out.write(new KmerStart(refName, seq.getSeqName(), seq.getSeqName(), kmer, 1, pos, translQuery,
                        (translQuery ? ProteinUtils.getInstance().translateToProtein(kmer, true, translTable)
                                : null)));

            }
        }
        seqReader.close();
    }
    out.close();
}

From source file:com.thinkbiganalytics.kerberos.TestKerberosKinit.java

public static void main(String[] args) throws Exception {
    final TestKerberosKinit testKerberosKinit = new TestKerberosKinit();
    Scanner scanner = new Scanner(System.in);

    System.out.println(" ");
    System.out.print("Which environment are you in? Enter 1 for HDP or 2 for Cloudera: ");
    String environmentCode = scanner.nextLine();
    if (StringUtils.isEmpty(environmentCode)) {
        environmentCode = "1";
    }/*from  w  w w  .ja v  a2s .c  o m*/

    String environment;
    switch (environmentCode) {
    case "1":
        environment = ENVIRONMENT_HDP;
        break;
    case "2":
        environment = ENVIRONMENT_CLOUDERA;
        break;
    default:
        throw new Exception("Invalid environment code");
    }

    System.out.println(" ");
    System.out.println(
            "Hit enter to default to: /etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml,/usr/hdp/current/hive-client/conf/hive-site.xml");
    System.out.print("Please enter the list of configuration resources: ");
    String configResources = scanner.nextLine();
    if (StringUtils.isEmpty(configResources)) {
        configResources = "/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml,/usr/hdp/current/hive-client/conf/hive-site.xml";
    }

    System.out.println(" ");
    System.out.println("Hit enter to default to: /etc/security/keytabs/hive-thinkbig.headless.keytab");
    System.out.print("Please enter the keytab file location: ");
    String keytab = scanner.nextLine();
    if (StringUtils.isEmpty(keytab)) {
        keytab = "/etc/security/keytabs/hive-thinkbig.headless.keytab";
    }

    System.out.println(" ");
    System.out.println("Hit enter to default to: hive/sandbox.hortonworks.com@sandbox.hortonworks.com");
    System.out.print("Please enter the real user principal name: ");
    String realUserPrincipal = scanner.nextLine();
    if (StringUtils.isEmpty(realUserPrincipal)) {
        realUserPrincipal = "hive/sandbox.hortonworks.com@sandbox.hortonworks.com";
    }

    System.out.println(" ");
    System.out.println("Please enter Y/N (default is N)");
    System.out.print("Do you want to test with a proxy user: ");
    String proxyUser = scanner.nextLine();
    if (StringUtils.isEmpty(realUserPrincipal)) {
        proxyUser = "N";
    }

    System.out.println(" ");
    System.out.println("Hit enter to default to: hdfs://sandbox.hortonworks.com:8020");
    System.out.print("Please enter the HDFS URL: ");
    String hdfsUrl = scanner.nextLine();
    if (StringUtils.isEmpty(hdfsUrl)) {
        hdfsUrl = "hdfs://sandbox.hortonworks.com:8020";
    }

    System.out.println(" ");
    System.out.println("Hit enter to default to: jdbc:hive2://localhost:10000/default");
    System.out.print("Please enter the Hive base connection string: ");
    String hiveHost = scanner.nextLine();
    if (StringUtils.isEmpty(hiveHost)) {
        hiveHost = "jdbc:hive2://localhost:10000/default";
    }

    String proxyUserName = null;
    if ("Y".equalsIgnoreCase(proxyUser)) {
        System.out.println(" ");
        System.out.print("Please enter the proxy user: ");
        proxyUserName = scanner.next();
    }

    System.out.println(" ");
    System.out.println("Executing Kinit to generate a kerberos ticket");

    if ("Y".equalsIgnoreCase(proxyUser)) {
        System.out.println("Testing with the proxy user: " + proxyUserName);
        testKerberosKinit.testHdfsWithUserImpersonation(configResources, keytab, realUserPrincipal,
                proxyUserName, environment, hdfsUrl);

        //testKerberosKinit.testHiveJdbcConnectionWithUserImpersonation(configResources, keytab, realUserPrincipal, proxyUserName);
        testKerberosKinit.testHiveJdbcConnection(configResources, keytab, realUserPrincipal, proxyUserName,
                hiveHost);
    } else {
        System.out.println("No Proxy User");
        testKerberosKinit.testHdfsAsKerberosUser(configResources, keytab, realUserPrincipal, environment,
                hdfsUrl);
        testKerberosKinit.testHiveJdbcConnection(configResources, keytab, realUserPrincipal, null, hiveHost);
    }
}

From source file:edu.msu.cme.rdp.probematch.cli.PrimerMatch.java

public static void main(String[] args) throws Exception {

    PrintStream out = new PrintStream(System.out);
    int maxDist = Integer.MAX_VALUE;

    try {/*from ww w . ja  v a 2 s  .  c  om*/
        CommandLine line = new PosixParser().parse(options, args);
        if (line.hasOption("outFile")) {
            out = new PrintStream(new File(line.getOptionValue("outFile")));
        }
        if (line.hasOption("maxDist")) {
            maxDist = Integer.valueOf(line.getOptionValue("maxDist"));
        }
        args = line.getArgs();

        if (args.length != 2) {
            throw new Exception("Unexpected number of command line arguments");
        }
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        new HelpFormatter().printHelp("PrimerMatch <primer_list | primer_file> <seq_file>", options);
        return;
    }

    List<PatternBitMask64> primers = new ArrayList();
    if (new File(args[0]).exists()) {
        File primerFile = new File(args[0]);
        SequenceFormat seqformat = SeqUtils.guessFileFormat(primerFile);

        if (seqformat.equals(SequenceFormat.FASTA)) {
            SequenceReader reader = new SequenceReader(primerFile);
            Sequence seq;

            while ((seq = reader.readNextSequence()) != null) {
                primers.add(new PatternBitMask64(seq.getSeqString(), true, seq.getSeqName()));
            }
            reader.close();
        } else {
            BufferedReader reader = new BufferedReader(new FileReader(args[0]));
            String line;

            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (!line.equals("")) {
                    primers.add(new PatternBitMask64(line, true));
                }
            }
            reader.close();
        }
    } else {
        for (String primer : args[0].split(",")) {
            primers.add(new PatternBitMask64(primer, true));
        }
    }

    SeqReader seqReader = new SequenceReader(new File(args[1]));
    Sequence seq;
    String primerRegion;

    out.println("#seqname\tdesc\tprimer_index\tprimer_name\tposition\tmismatches\tseq_primer_region");
    while ((seq = seqReader.readNextSequence()) != null) {
        for (int index = 0; index < primers.size(); index++) {
            PatternBitMask64 primer = primers.get(index);
            BitVector64Result results = BitVector64.process(seq.getSeqString().toCharArray(), primer, maxDist);

            for (BitVector64Match result : results.getResults()) {
                primerRegion = seq.getSeqString().substring(
                        Math.max(0, result.getPosition() - primer.getPatternLength()), result.getPosition());

                if (result.getPosition() < primer.getPatternLength()) {
                    for (int pad = result.getPosition(); pad < primer.getPatternLength(); pad++) {
                        primerRegion = "x" + primerRegion;
                    }
                }

                out.println(seq.getSeqName() + "\t" + seq.getDesc() + "\t" + (index + 1) + "\t"
                        + primer.getPrimerName() + "\t" + result.getPosition() + "\t" + result.getScore() + "\t"
                        + primerRegion);
            }
        }
    }
    out.close();
    seqReader.close();
}