List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:edu.umn.msi.tropix.proteomics.tools.MzXMLToMGF.java
public static void main(final String[] args) throws Exception { final MzXMLToMGFConverter converter = new MzXMLToMGFConverterStreamingImpl(); final String baseName = FilenameUtils.getBaseName(args[0]); final File mgfFile = new File(baseName + ".mgf"); final FileInputStream inputStream = FILE_UTILS.getFileInputStream(args[0]); final FileOutputStream outputStream = new FileOutputStream(mgfFile); try {//from w w w . ja va2 s . c o m converter.mzxmlToMGF(inputStream, outputStream, null); } finally { IO_UTILS.closeQuietly(outputStream); IO_UTILS.closeQuietly(inputStream); } }
From source file:com.textocat.textokit.postagger.opennlp.PackageModelZipAsArtifact.java
public static void main(String[] args) throws IOException { PackageModelZipAsArtifact cli = new PackageModelZipAsArtifact(); new JCommander(cli, args); Path inputZipPath = Paths.get(cli.inputZipPathStr); if (!Files.isRegularFile(inputZipPath)) { System.err.println(inputZipPath + " is not an existing file."); System.exit(1);/*www . j a va 2s .c o m*/ } POSModelJarManifestBean manifestBean = new POSModelJarManifestBean(cli.languageCode, cli.modelVariant); Path outputJarPath = inputZipPath .resolveSibling(FilenameUtils.getBaseName(inputZipPath.getFileName().toString()) + ".jar"); try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputJarPath))) { JarOutputStream jout = new JarOutputStream(out, manifestBean.toManifest()); jout.putNextEntry(new ZipEntry(ClasspathPOSModelHolder.getClassPath(manifestBean.getLanguageCode(), manifestBean.getModelVariant()))); FileUtils.copyFile(inputZipPath.toFile(), jout); jout.closeEntry(); jout.close(); } }
From source file:compressor.Compressor.java
/** * @param args the command line arguments * * args[0] is the file path including the filename * * * args[1] is the base folder/*from w w w . j ava 2s. c om*/ * * * args[2] is the path to the pdf * @throws java.io.IOException * @throws java.io.FileNotFoundException * @throws org.apache.pdfbox.exceptions.COSVisitorException */ public static void main(String[] args) throws IOException, FileNotFoundException, COSVisitorException { if (args[0] != null && args[1] != null && args[2] != null) { Compressor cp = new Compressor(); String src = args[0]; try { String image_name = FilenameUtils.getBaseName(args[0]); // @param1 is the full filepath // @param2 is the base folder which is the e.g. /home/mxp/Pictures/ // @param3 is the naked image name without extension cp.extract_images(src, args[1], image_name); // @param1 is the src extracted path // @param2 is the compressed path cp.compress_images(args[1] + "img/", args[1]); } catch (Exception e) { } finally { FileUtils.cleanDirectory(new File(args[1] + "img/")); FileUtils.cleanDirectory(new File(args[1] + "compressed/")); } } else { System.out.println("parameters are missing"); } }
From source file:bpgead2pdf.java
/** * Main method./*from w w w. j a va 2s . c o m*/ * @param args command-line arguments */ public static void main(String[] args) { try { System.out.println("Preparing..."); // Setup directories File baseDir = new File("."); File outDir = new File(baseDir, "out"); outDir.mkdirs(); // Setup input and output files File xmlfile = new File(args[0]); String xsltfile = new String("http://www.library.yale.edu/facc/xsl/fo/yul.ead2002.pdf.xsl"); String pdffn = new String(FilenameUtils.getBaseName(args[0]) + ".pdf"); File pdffile = new File(outDir, pdffn); System.out.println("Input: XML (" + xmlfile + ")"); System.out.println("Stylesheet: " + xsltfile); System.out.println("Output: PDF (" + pdffile + ")"); System.out.println(); System.out.println("Transforming..."); // configure fopFactory as desired FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); // configure foUserAgent as desired // configure XSLT Processor Processor processor = new Processor(false); // Setup output OutputStream out = new java.io.FileOutputStream(pdffile); out = new java.io.BufferedOutputStream(out); try { // Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); // Setup XSLT XsltCompiler compiler = processor.newXsltCompiler(); XsltExecutable transform = compiler.compile(new StreamSource(xsltfile)); XsltTransformer transformer = transform.load(); // Set the value of a <param> in the stylesheet // transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP SAXDestination res = new SAXDestination(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.setDestination(res); transformer.setSource(src); transformer.transform(); } finally { out.close(); } System.out.println("Success!"); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } }
From source file:de.fosd.jdime.JDimeWrapper.java
public static void main(String[] args) throws IOException, InterruptedException { // setup logging Logger root = Logger.getLogger(JDimeWrapper.class.getPackage().getName()); root.setLevel(Level.WARNING); for (Handler handler : root.getHandlers()) { handler.setLevel(Level.WARNING); }//from ww w. ja v a 2 s .c o m // setup JDime using the MergeContext MergeContext context = new MergeContext(); context.setPretend(true); context.setQuiet(false); // prepare the list of input files ArtifactList<FileArtifact> inputArtifacts = new ArtifactList<>(); for (String filename : args) { try { File file = new File(filename); // the revision name, this will be used as condition for ifdefs // as an example, I'll just use the filenames Revision rev = new Revision(FilenameUtils.getBaseName(file.getPath())); FileArtifact newArtifact = new FileArtifact(rev, file); inputArtifacts.add(newArtifact); } catch (FileNotFoundException e) { System.err.println("Input file not found: " + filename); } } context.setInputFiles(inputArtifacts); // setup strategies MergeStrategy<FileArtifact> structured = new StructuredStrategy(); MergeStrategy<FileArtifact> conditional = new NWayStrategy(); // run the merge first with structured strategy to see whether there are conflicts context.setMergeStrategy(structured); context.collectStatistics(true); Operation<FileArtifact> merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null, null, context.isConditionalMerge()); merge.apply(context); // if there are no conflicts, run the conditional strategy if (context.getStatistics().hasConflicts()) { context = new MergeContext(context); context.collectStatistics(false); context.setMergeStrategy(conditional); // use regular merging outside of methods context.setConditionalOutsideMethods(false); // we have to recreate the operation because now we will do a conditional merge merge = new MergeOperation<>(context.getInputFiles(), context.getOutputFile(), null, null, context.isConditionalMerge()); merge.apply(context); } }
From source file:com.googlecode.dex2jar.v3.Main.java
public static void main(String... args) { System.err.println("this cmd is deprecated, use the d2j-dex2jar if possible"); System.out.println("dex2jar version: translator-" + Main.class.getPackage().getImplementationVersion()); if (args.length == 0) { System.err.println("dex2jar file1.dexORapk file2.dexORapk ..."); return;/*from w ww . java 2s .co m*/ } String jreVersion = System.getProperty("java.specification.version"); if (jreVersion.compareTo("1.6") < 0) { System.err.println("A JRE version >=1.6 is required"); return; } boolean containsError = false; for (String file : args) { File dex = new File(file); final File gen = new File(dex.getParentFile(), FilenameUtils.getBaseName(file) + "_dex2jar.jar"); System.out.println("dex2jar " + dex + " -> " + gen); try { doFile(dex, gen); } catch (Exception e) { containsError = true; niceExceptionMessage(new DexException(e, "while process file: [%s]", dex), 0); } } System.out.println("Done."); System.exit(containsError ? -1 : 0); }
From source file:diffhunter.DiffHunter.java
/** * @param args the command line arguments * @throws org.apache.commons.cli.ParseException * @throws java.io.IOException/*from w w w . ja v a2 s.c o m*/ */ public static void main(String[] args) throws ParseException, IOException { //String test_ = Paths.get("J:\\VishalData\\additional\\", "Sasan" + "_BDB").toAbsolutePath().toString(); // TODO code application logic here /*args = new String[] { "-i", "-b", "J:\\VishalData\\additional\\Ptbp2_E18_5_cortex_CLIP_mm9_plus_strand_sorted.bed", "-r", "J:\\VishalData\\additional\\mouse_mm9.txt", "-o", "J:\\VishalData" };*/ /*args = new String[] { "-c", "-r", "J:\\VishalData\\additional\\mouse_mm9.txt", "-1", "J:\\VishalData\\Ptbp2_Adult_testis_CLIP_mm9_plus_strand_sorted_BDB", "-2", "J:\\VishalData\\Ptbp2_E18_5_cortex_CLIP_mm9_plus_strand_sorted_BDB", "-w", "200", "-s", "50", "-o", "J:\\VishalData" };*/ Options options = new Options(); // add t option options.addOption("i", "index", false, "Indexing BED files."); options.addOption("b", "bed", true, "bed file to be indexed"); options.addOption("o", "output", true, "Folder that the index/comparison file will be created."); options.addOption("r", "reference", true, "Reference annotation file to be used for indexing"); options.addOption("c", "compare", false, "Finding differences between two conditions"); options.addOption("1", "first", true, "First sample index location"); options.addOption("2", "second", true, "Second sample index location"); options.addOption("w", "window", true, "Length of window for identifying differences"); options.addOption("s", "sliding", true, "Length of sliding"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); boolean indexing = false; boolean comparing = false; //Indexing! if (cmd.hasOption("i")) { //if(cmd.hasOption("1")) //System.err.println("sasan"); //System.out.println("sasa"); indexing = true; } else if (cmd.hasOption("c")) { //System.err.println(""); comparing = true; } else { //System.err.println("Option is not deteced."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } //Indexing is selected // if (indexing == true) { //Since indexing is true. //User have to provide file for indexing. if (!(cmd.hasOption("o") || cmd.hasOption("r") || cmd.hasOption("b"))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } String bedfile_ = cmd.getOptionValue("b"); String reference_file = cmd.getOptionValue("r"); String folder_loc = cmd.getOptionValue("o"); String sample_name = FilenameUtils.getBaseName(bedfile_); try (Database B2 = BerkeleyDB_Box.Get_BerkeleyDB( Paths.get(folder_loc, sample_name + "_BDB").toAbsolutePath().toString(), true, sample_name)) { Indexer indexing_ = new Indexer(reference_file); indexing_.Make_Index(B2, bedfile_, Paths.get(folder_loc, sample_name + "_BDB").toAbsolutePath().toString()); B2.close(); } } else if (comparing == true) { if (!(cmd.hasOption("o") || cmd.hasOption("w") || cmd.hasOption("s") || cmd.hasOption("1") || cmd.hasOption("2"))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } String folder_loc = cmd.getOptionValue("o"); int window_ = Integer.parseInt(cmd.getOptionValue("w")); //int window_=600; int slide_ = Integer.parseInt(cmd.getOptionValue("s")); String first = cmd.getOptionValue("1").replace("_BDB", ""); String second = cmd.getOptionValue("2").replace("_BDB", ""); String reference_file = cmd.getOptionValue("r"); //String folder_loc=cmd.getOptionValue("o"); String sample_name_first = FilenameUtils.getBaseName(first); String sample_name_second = FilenameUtils.getBaseName(second); Database B1 = BerkeleyDB_Box.Get_BerkeleyDB(first + "_BDB", false, sample_name_first); Database B2 = BerkeleyDB_Box.Get_BerkeleyDB(second + "_BDB", false, sample_name_second); List<String> first_condition_genes = Files .lines(Paths.get(first + "_BDB", sample_name_first + ".txt").toAbsolutePath()) .collect(Collectors.toList()); List<String> second_condition_genes = Files .lines(Paths.get(second + "_BDB", sample_name_second + ".txt").toAbsolutePath()) .collect(Collectors.toList()); System.out.println("First and second condition are loaded!!! "); List<String> intersection_ = new ArrayList<>(first_condition_genes); intersection_.retainAll(second_condition_genes); BufferedWriter output = new BufferedWriter( new FileWriter(Paths.get(folder_loc, "differences_" + window_ + "_s" + slide_ + "_c" + ".txt") .toAbsolutePath().toString(), false)); List<Result_Window> final_results = Collections.synchronizedList(new ArrayList<>()); Worker_New worker_class = new Worker_New(); worker_class.Read_Reference(reference_file); while (!intersection_.isEmpty()) { List<String> selected_genes = new ArrayList<>(); //if (intersection_.size()<=10000){selected_genes.addAll(intersection_.subList(0, intersection_.size()));} //else selected_genes.addAll(intersection_.subList(0, 10000)); if (intersection_.size() <= intersection_.size()) { selected_genes.addAll(intersection_.subList(0, intersection_.size())); } else { selected_genes.addAll(intersection_.subList(0, intersection_.size())); } intersection_.removeAll(selected_genes); //System.out.println("Intersection count is:"+intersection_.size()); //final List<Result_Window> resultssss_=new ArrayList<>(); IntStream.range(0, selected_genes.size()).parallel().forEach(i -> { System.out.println(selected_genes.get(i) + "\tprocessing......"); String gene_of_interest = selected_genes.get(i);//"ENSG00000142657|PGD";//intersection_.get(6);////"ENSG00000163395|IGFN1";//"ENSG00000270066|SCARNA2"; int start = worker_class.dic_genes.get(gene_of_interest).start_loc; int end = worker_class.dic_genes.get(gene_of_interest).end_loc; Map<Integer, Integer> first_ = Collections.EMPTY_MAP; try { first_ = BerkeleyDB_Box.Get_Coord_Read(B1, gene_of_interest); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(DiffHunter.class.getName()).log(Level.SEVERE, null, ex); } Map<Integer, Integer> second_ = Collections.EMPTY_MAP; try { second_ = BerkeleyDB_Box.Get_Coord_Read(B2, gene_of_interest); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(DiffHunter.class.getName()).log(Level.SEVERE, null, ex); } List<Window> top_windows_first = worker_class.Get_Top_Windows(window_, first_, slide_); List<Window> top_windows_second = worker_class.Get_Top_Windows(window_, second_, slide_); //System.out.println("passed for window peak call for gene \t"+selected_genes.get(i)); // System.out.println("top_window_first_Count\t"+top_windows_first.size()); // System.out.println("top_window_second_Count\t"+top_windows_second.size()); if (top_windows_first.isEmpty() && top_windows_second.isEmpty()) { return; } List<Result_Window> res_temp = new Worker_New().Get_Significant_Windows(gene_of_interest, start, end, top_windows_first, top_windows_second, second_, first_, sample_name_first, sample_name_second, 0.01); if (!res_temp.isEmpty()) { final_results.addAll(res_temp);//final_results.addAll(worker_class.Get_Significant_Windows(gene_of_interest, start, end, top_windows_first, top_windows_second, second_, first_, first_condition, second_condition, 0.01)); } //System.out.println(selected_genes.get(i)+"\tprocessed."); }); /*selected_genes.parallelStream().forEach(i -> { });*/ List<Double> pvals = new ArrayList<>(); for (int i = 0; i < final_results.size(); i++) { pvals.add(final_results.get(i).p_value); } List<Double> qvals = MultipleTestCorrection.benjaminiHochberg(pvals); System.out.println("Writing to file..."); output.append("Gene_Symbol\tContributing_Sample\tStart\tEnd\tOddsRatio\tp_Value\tFDR"); output.newLine(); for (int i = 0; i < final_results.size(); i++) { Result_Window item = final_results.get(i); output.append(item.associated_gene_symbol + "\t" + item.contributing_windows + "\t" + item.start_loc + "\t" + item.end_loc + "\t" + item.oddsratio_ + "\t" + item.p_value + "\t" + qvals.get(i)); //+ "\t" + item.average_other_readcount_cotributing + "\t" + item.average_other_readcount_cotributing + "\t" + item.average_window_readcount_non + "\t" + item.average_other_readcount_non); output.newLine(); } /* for (Result_Window item : final_results) { output.append(item.associated_gene_symbol + "\t" + item.contributing_windows + "\t" + item.start_loc + "\t" + item.end_loc + "\t" + item.oddsratio_ + "\t" + item.p_value); //+ "\t" + item.average_other_readcount_cotributing + "\t" + item.average_other_readcount_cotributing + "\t" + item.average_window_readcount_non + "\t" + item.average_other_readcount_non); output.newLine(); } */ final_results.clear(); } output.close(); } System.out.println("Done."); }
From source file:bboss.org.artofsolving.jodconverter.cli.Convert.java
public static void main(String[] arguments) throws ParseException, JSONException, IOException { CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments); String outputFormat = null;// ww w.ja v a2 s .com if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) { outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt()); } int port = DEFAULT_OFFICE_PORT; if (commandLine.hasOption(OPTION_PORT.getOpt())) { port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt())); } String[] fileNames = commandLine.getArgs(); if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) { String syntax = "java -jar jodconverter-core.jar [options] input-file output-file\n" + "or [options] -o output-format input-file [input-file...]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(syntax, OPTIONS); System.exit(STATUS_INVALID_ARGUMENTS); } DocumentFormatRegistry registry; if (commandLine.hasOption(OPTION_REGISTRY.getOpt())) { File registryFile = new File(commandLine.getOptionValue(OPTION_REGISTRY.getOpt())); registry = new JsonDocumentFormatRegistry(FileUtils.readFileToString(registryFile)); } else { registry = new DefaultDocumentFormatRegistry(); } DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); configuration.setPortNumber(port); if (commandLine.hasOption(OPTION_TIMEOUT.getOpt())) { int timeout = Integer.parseInt(commandLine.getOptionValue(OPTION_TIMEOUT.getOpt())); configuration.setTaskExecutionTimeout(timeout * 1000); } if (commandLine.hasOption(OPTION_USER_PROFILE.getOpt())) { String templateProfileDir = commandLine.getOptionValue(OPTION_USER_PROFILE.getOpt()); configuration.setTemplateProfileDir(new File(templateProfileDir)); } OfficeManager officeManager = configuration.buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, registry); try { if (outputFormat == null) { File inputFile = new File(fileNames[0]); File outputFile = new File(fileNames[1]); converter.convert(inputFile, outputFile); } else { for (int i = 0; i < fileNames.length; i++) { File inputFile = new File(fileNames[i]); String outputName = FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat; File outputFile = new File(FilenameUtils.getFullPath(fileNames[i]) + outputName); converter.convert(inputFile, outputFile); } } } finally { officeManager.stop(); } }
From source file:com.artofsolving.jodconverter.cli.ConvertDocument.java
public static void main(String[] arguments) throws Exception { CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments); int port = SocketOpenOfficeConnection.DEFAULT_PORT; if (commandLine.hasOption(OPTION_PORT.getOpt())) { port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt())); }/*from w ww.j ava2 s .c om*/ String outputFormat = null; if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) { outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt()); } boolean verbose = false; if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) { verbose = true; } DocumentFormatRegistry registry; if (commandLine.hasOption(OPTION_XML_REGISTRY.getOpt())) { File registryFile = new File(commandLine.getOptionValue(OPTION_XML_REGISTRY.getOpt())); if (!registryFile.isFile()) { System.err.println("ERROR: specified XML registry file not found: " + registryFile); System.exit(EXIT_CODE_XML_REGISTRY_NOT_FOUND); } registry = new XmlDocumentFormatRegistry(new FileInputStream(registryFile)); if (verbose) { System.out.println("-- loaded document format registry from " + registryFile); } } else { registry = new DefaultDocumentFormatRegistry(); } String[] fileNames = commandLine.getArgs(); if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) { String syntax = "convert [options] input-file output-file; or\n" + "[options] -f output-format input-file [input-file...]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(syntax, OPTIONS); System.exit(EXIT_CODE_TOO_FEW_ARGS); } OpenOfficeConnection connection = new SocketOpenOfficeConnection(port); try { if (verbose) { System.out.println("-- connecting to OpenOffice.org on port " + port); } connection.connect(); } catch (ConnectException officeNotRunning) { System.err.println( "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port " + port + "."); System.exit(EXIT_CODE_CONNECTION_FAILED); } try { DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry); if (outputFormat == null) { File inputFile = new File(fileNames[0]); File outputFile = new File(fileNames[1]); convertOne(converter, inputFile, outputFile, verbose); } else { for (int i = 0; i < fileNames.length; i++) { File inputFile = new File(fileNames[i]); File outputFile = new File(FilenameUtils.getFullPath(fileNames[i]) + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat); convertOne(converter, inputFile, outputFile, verbose); } } } finally { if (verbose) { System.out.println("-- disconnecting"); } connection.disconnect(); } }
From source file:DokeosConverter.java
public static void main(String[] arguments) throws Exception { CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments); int port = SocketOpenOfficeConnection.DEFAULT_PORT; if (commandLine.hasOption(OPTION_PORT.getOpt())) { port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt())); }/*from w ww. j a v a 2s. c om*/ String outputFormat = null; if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) { outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt()); } boolean verbose = false; if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) { verbose = true; } String dokeosMode = "woogie"; if (commandLine.hasOption(OPTION_DOKEOS_MODE.getOpt())) { dokeosMode = commandLine.getOptionValue(OPTION_DOKEOS_MODE.getOpt()); } int width = 800; if (commandLine.hasOption(OPTION_WIDTH.getOpt())) { width = Integer.parseInt(commandLine.getOptionValue(OPTION_WIDTH.getOpt())); } int height = 600; if (commandLine.hasOption(OPTION_HEIGHT.getOpt())) { height = Integer.parseInt(commandLine.getOptionValue(OPTION_HEIGHT.getOpt())); } String[] fileNames = commandLine.getArgs(); if ((outputFormat == null && fileNames.length != 2 && dokeosMode != null) || fileNames.length < 1) { String syntax = "convert [options] input-file output-file; or\n" + "[options] -f output-format input-file [input-file...]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(syntax, OPTIONS); System.exit(EXIT_CODE_TOO_FEW_ARGS); } OpenOfficeConnection connection = new DokeosSocketOfficeConnection(port); try { if (verbose) { System.out.println("-- connecting to OpenOffice.org on port " + port); } connection.connect(); } catch (ConnectException officeNotRunning) { System.err.println( "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port " + port + "."); System.exit(EXIT_CODE_CONNECTION_FAILED); } try { // choose the good constructor to deal with the conversion DocumentConverter converter; if (dokeosMode.equals("oogie")) { converter = new OogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height); } else if (dokeosMode.equals("woogie")) { converter = new WoogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height); } else { converter = new OpenOfficeDocumentConverter(connection); } if (outputFormat == null) { File inputFile = new File(fileNames[0]); File outputFile = new File(fileNames[1]); convertOne(converter, inputFile, outputFile, verbose); } else { for (int i = 0; i < fileNames.length; i++) { File inputFile = new File(fileNames[i]); File outputFile = new File(FilenameUtils.getFullPath(fileNames[i]) + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat); convertOne(converter, inputFile, outputFile, verbose); } } } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) { connection.disconnect(); System.err.println("ERROR: conversion failed."); System.exit(EXIT_CODE_CONVERSION_FAILED); } finally { if (verbose) { System.out.println("-- disconnecting"); } connection.disconnect(); } }