Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

In this page you can find the example usage for java.io File getAbsolutePath.

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) {

    File workingDirectory = new File("C:" + File.separator + "Invoices");

    File template = new File(workingDirectory.getAbsolutePath() + File.separator + "invoiceTemplate.tex");

    File tempDir = new File(workingDirectory.getAbsolutePath() + File.separator + "temp");
    if (!tempDir.isDirectory()) {
        tempDir.mkdir();// ww w.  j av  a 2 s . c  o  m
    }

    File invoice1 = new File(tempDir.getAbsolutePath() + File.separator + "invoice1.tex");
    File invoice2 = new File(tempDir.getAbsolutePath() + File.separator + "invoice2.tex");

    try {

        HashMap<String, String> data = new HashMap<String, String>();

        data.put("Number", "1");
        data.put("Customer name", "Ivan Pfeiffer");
        data.put("Customer street", "Schwarzer Weg 4");
        data.put("Customer zip", "13505 Berlin");
        data.put("Development", "Software");
        data.put("Price", "500");

        JLRConverter converter = new JLRConverter("::", ":::");
        if (!converter.parse(template, invoice1, data)) {
            System.out.println(converter.getErrorMessage());
        }

        data.put("Number", "2");
        data.put("Customer name", "Mike Mueller");
        data.put("Customer street", "Prenzlauer Berg 12");
        data.put("Customer zip", "10405 Berlin");
        data.put("Development", "Hardware");
        data.put("Price", "2350");

        if (!converter.parse(template, invoice2, data)) {
            System.out.println(converter.getErrorMessage());
        }

        File desktop = new File(System.getProperty("user.home") + File.separator + "Desktop");

        JLRGenerator pdfGen = new JLRGenerator();

        pdfGen.deleteTempTexFile(false);

        if (!pdfGen.generate(invoice1, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

        if (!pdfGen.generate(invoice2, desktop, workingDirectory)) {
            System.out.println(pdfGen.getErrorMessage());
        }

        JLROpener.open(pdfGen.getPDF());

    } catch (IOException ex) {
        System.err.println(ex.getMessage());
    }
}

From source file:org.apache.rya.jena.jenasesame.example.JenaSesameExample.java

public static void main(final String args[]) throws Exception {
    Repository repo = null;//from w w  w .java 2  s.  co  m
    RepositoryConnection addConnection = null;
    RepositoryConnection queryConnection = null;
    QueryExecution queryExecution = null;
    try {
        repo = new SailRepository(new MemoryStore());
        repo.initialize();

        // Load some data.
        addConnection = repo.getConnection();

        // Reads files relative from target/test-classes which should have been copied from src/test/resources
        final URL url = ClassLoader.getSystemResource("rdf_format_files/turtle_files/turtle_data.ttl");
        final File file = ResourceUtils.getFile(url);
        final String fileName = file.getAbsolutePath();
        final RDFFormat rdfFormat = RDFFormat.forFileName(fileName);

        log.info("Added RDF file with " + rdfFormat.getName() + " format: " + fileName);
        addConnection.add(file, "http://base/", rdfFormat);
        addConnection.close();

        queryConnection = repo.getConnection();

        final Dataset dataset = JenaSesame.createDataset(queryConnection);

        final Model model = dataset.getDefaultModel();
        log.info(model.getNsPrefixMap());

        final String object = "susandillon@gmail.com";
        final String queryString = "prefix : <http://example/> SELECT * { ?s ?p '" + object + "' }";
        final Query query = QueryFactory.create(queryString);
        queryExecution = QueryExecutionFactory.create(query, dataset);
        QueryExecUtils.executeQuery(query, queryExecution);
    } catch (final Exception e) {
        log.error("Encountered an exception while performing query.", e);
    } finally {
        if (queryExecution != null) {
            queryExecution.close();
        }
        if (addConnection != null) {
            addConnection.close();
        }
        if (queryConnection != null) {
            queryConnection.close();
        }
        if (repo != null) {
            repo.shutDown();
        }
    }
}

From source file:TestDumpRecord.java

public static void main(String[] args) throws NITFException {
    List<String> argList = Arrays.asList(args);
    List<File> files = new LinkedList<File>();
    for (String arg : argList) {
        File f = new File(arg);
        if (f.isDirectory()) {
            File[] dirFiles = f.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    String ext = FilenameUtils.getExtension(name).toLowerCase();
                    return ext.matches("nitf|nsf|ntf");
                }//ww  w .  ja  v  a 2s.c o m
            });
            files.addAll(Arrays.asList(dirFiles));
        } else
            files.add(f);
    }

    Reader reader = new Reader();
    for (File file : files) {
        PrintStream out = System.out;

        out.println("=== " + file.getAbsolutePath() + " ===");
        IOHandle handle = new IOHandle(file.getAbsolutePath());
        Record record = reader.read(handle);
        dumpRecord(record, reader, out);
        handle.close();

        record.destruct(); // tells the memory manager to decrement the ref
        // count
    }
}

From source file:com.tonygalati.sprites.SpriteGenerator.java

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

    //        if (args.length != 3)
    //        {//w  w w .j  a  va  2  s .c o  m
    //           System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n");
    //           System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n");
    //           System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n");
    //           System.out.print("most browsers.\n\n");
    //           return;
    //        }

    //        Integer margin = Integer.parseInt(args[1]);
    Integer margin = Integer.parseInt("1");
    String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png";
    SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator();

    ClassLoader classLoader = SpriteGenerator.class.getClassLoader();
    URL folderPath = classLoader.getResource(NAIC_SMALL_ICON);
    if (folderPath != null) {
        File imageFolder = new File(folderPath.getPath());

        // Read images
        ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();
        Integer yCoordinate = null;

        for (File f : imageFolder.listFiles()) {
            if (f.isFile()) {
                String fileName = f.getName();
                String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());

                if (ext.equals("png")) {
                    System.out.println("adding file " + fileName);
                    BufferedImage image = ImageIO.read(f);
                    imageList.add(image);

                    if (yCoordinate == null) {
                        yCoordinate = 0;
                    } else {
                        yCoordinate += (image.getHeight() + margin);
                    }

                    // add to cssGenerator
                    cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate);
                }
            }
        }

        // Find max width and total height
        int maxWidth = 0;
        int totalHeight = 0;

        for (BufferedImage image : imageList) {
            totalHeight += image.getHeight() + margin;

            if (image.getWidth() > maxWidth)
                maxWidth = image.getWidth();
        }

        System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(),
                totalHeight, maxWidth);

        // Create the actual sprite
        BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB);

        int currentY = 0;
        Graphics g = sprite.getGraphics();
        for (BufferedImage image : imageList) {
            g.drawImage(image, 0, currentY, null);
            currentY += image.getHeight() + margin;
        }

        System.out.format("Writing sprite: %s%n", spriteFile);
        ImageIO.write(sprite, "png", new File(spriteFile));
        File cssFile = cssGenerator.getFile(spriteFile);
        System.out.println(cssFile.getAbsolutePath() + " created");
    } else {
        System.err.println("Could not find folder: " + NAIC_SMALL_ICON);

    }

}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.TrafficRouterStart.java

public static void main(String[] args) throws Exception {
    System.setProperty("deploy.dir", "src/test");
    System.setProperty("dns.zones.dir", "src/test/var/auto-zones");

    LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN);
    LogManager.getLogger("org.springframework").setLevel(Level.WARN);

    ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%d{ISO8601} [%-5p] %c{4}: %m%n"));
    LogManager.getRootLogger().addAppender(consoleAppender);
    LogManager.getRootLogger().setLevel(Level.INFO);

    File webAppDirectory = new File("src/main/webapp");
    if (!webAppDirectory.exists()) {
        LogManager.getRootLogger().fatal(webAppDirectory.getAbsolutePath()
                + " does not exist, are you running TrafficRouterStart from the correct directory?");
        System.exit(1);/*  w w w .  ja v  a  2 s  .  c  o m*/
    }

    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8081);
    server.addConnector(connector);

    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.l2jserver.tool.conversor.itemtemplate.ItemTemplateConversor.java

public static void main(String[] args) throws IOException {
    template = IOUtils.toString(ItemTemplateConversor.class.getResourceAsStream("ItemTemplateBase.txt"));

    Collection<File> files = FileUtils.listFiles(
            new File("/home/rogiel/Documents/Eclipse/lineage2/L2J_DataPack_BETA/data/stats/items"),
            new String[] { "xml" }, false);

    for (final File file : files) {
        processFile(file.getAbsolutePath());
    }// w ww . j  a va2  s. c o  m
}

From source file:bixo.tools.LengthenUrlsTool.java

/**
 * @param args - URL to fetch, or path to file of URLs
 *///from w  w  w .jav a2  s  .  com
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
    try {
        String url = null;
        if (args.length == 0) {
            System.out.print("URL to lengthen: ");
            url = readInputLine();
            if (url.length() == 0) {
                System.exit(0);
            }

            if (!url.startsWith("http://")) {
                url = "http://" + url;
            }
        } else if (args.length != 1) {
            System.out.print("A single URL or filename parameter is allowed");
            System.exit(0);
        } else {
            url = args[0];
        }

        String filename;
        if (!url.startsWith("http://")) {
            // It's a path to a file of URLs
            filename = url;
        } else {
            // We have a URL that we need to write to a temp file.
            File tempFile = File.createTempFile("LengthenUrlsTool", "txt");
            filename = tempFile.getAbsolutePath();
            FileWriter fw = new FileWriter(tempFile);
            IOUtils.write(url, fw);
            fw.close();
        }

        System.setProperty("bixo.root.level", "TRACE");
        // Uncomment this to see the wire log for HttpClient
        // System.setProperty("bixo.http.level", "DEBUG");

        BaseFetcher fetcher = UrlLengthener.makeFetcher(10, ConfigUtils.BIXO_TOOL_AGENT);

        Pipe pipe = new Pipe("urls");
        pipe = new Each(pipe, new UrlLengthener(fetcher));
        pipe = new Each(pipe, new Debug());

        BixoPlatform platform = new BixoPlatform(LengthenUrlsTool.class, Platform.Local);
        BasePath filePath = platform.makePath(filename);
        TextLine textLineLocalScheme = new TextLine(new Fields("url"));
        Tap sourceTap = platform.makeTap(textLineLocalScheme, filePath, SinkMode.KEEP);
        SinkTap sinkTap = new NullSinkTap(new Fields("url"));

        FlowConnector flowConnector = platform.makeFlowConnector();
        Flow flow = flowConnector.connect(sourceTap, sinkTap, pipe);

        flow.complete();
    } catch (Exception e) {
        System.err.println("Exception running tool: " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(-1);
    }
}

From source file:de.doering.dwca.clemens.ChecklistBuilder.java

public static void main(String[] args) throws IOException {
    ChecklistBuilder builder = new ChecklistBuilder();
    File archive = builder.build();
    System.out.println("Archive generated at " + archive.getAbsolutePath());
}

From source file:org.apache.rya.jena.jenasesame.example.JenaReasoningWithRulesExample.java

public static void main(final String args[]) throws Exception {
    Repository repo = null;/*  ww  w.  j a  v a 2 s .c  om*/
    RepositoryConnection addConnection = null;
    RepositoryConnection queryConnection = null;
    try {
        repo = new SailRepository(new MemoryStore());
        repo.initialize();

        // Load some data.
        addConnection = repo.getConnection();

        // Reads files relative from target/test-classes which should have been copied from src/test/resources
        final URL url = ClassLoader.getSystemResource("rdf_format_files/notation3_files/n3_data.n3");
        final File file = ResourceUtils.getFile(url);
        final String fileName = file.getAbsolutePath();
        final RDFFormat rdfFormat = RDFFormat.forFileName(fileName);

        log.info("Added RDF file with " + rdfFormat.getName() + " format: " + fileName);
        addConnection.add(file, "http://base/", rdfFormat);
        addConnection.close();

        queryConnection = repo.getConnection();

        final Dataset dataset = JenaSesame.createDataset(queryConnection);

        final Model model = dataset.getDefaultModel();
        log.info(model.getNsPrefixMap());

        final URL rulesUrl = ClassLoader
                .getSystemResource("rdf_format_files/notation3_files/rule_files/rules.txt");
        final File rulesFile = ResourceUtils.getFile(rulesUrl);
        final String rulesFileName = rulesFile.getAbsolutePath();

        final Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rulesFileName));

        final InfModel infModel = ModelFactory.createInfModel(reasoner, model);

        final StmtIterator iterator = infModel.listStatements();

        while (iterator.hasNext()) {
            final Statement stmt = iterator.nextStatement();

            final Resource subject = stmt.getSubject();
            final Property predicate = stmt.getPredicate();
            final RDFNode object = stmt.getObject();

            log.info(subject.toString() + " " + predicate.toString() + " " + object.toString());
        }
    } catch (final Exception e) {
        log.error("Encountered an exception while running reasoner.", e);
    } finally {
        if (addConnection != null) {
            addConnection.close();
        }
        if (queryConnection != null) {
            queryConnection.close();
        }
        if (repo != null) {
            repo.shutDown();
        }
    }
}

From source file:com.thoughtworks.go.server.DevelopmentServer.java

public static void main(String[] args) throws Exception {
    LogConfigurator logConfigurator = new LogConfigurator(DEFAULT_LOGBACK_CONFIGURATION_FILE);
    logConfigurator.initialize();//from   w w w  . j  a va 2  s.c  om
    copyDbFiles();
    copyPluginAssets();
    File webApp = new File("webapp");
    if (!webApp.exists()) {
        throw new RuntimeException("No webapp found in " + webApp.getAbsolutePath());
    }

    assertActivationJarPresent();
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(GENERATE_STATISTICS, "true");

    systemEnvironment.setProperty(SystemEnvironment.PARENT_LOADER_PRIORITY, "true");
    systemEnvironment.setProperty(SystemEnvironment.CRUISE_SERVER_WAR_PROPERTY, webApp.getAbsolutePath());
    systemEnvironment.set(SystemEnvironment.PLUGIN_LOCATION_MONITOR_INTERVAL_IN_SECONDS, 5);

    systemEnvironment.set(SystemEnvironment.DEFAULT_PLUGINS_ZIP, "/plugins.zip");
    systemEnvironment.set(SystemEnvironment.PLUGIN_ACTIVATOR_JAR_PATH, "go-plugin-activator.jar");
    systemEnvironment.set(SystemEnvironment.FAIL_STARTUP_ON_DATA_ERROR, true);
    systemEnvironment.setProperty(GoConstants.I18N_CACHE_LIFE, "0"); //0 means reload when stale
    systemEnvironment.set(SystemEnvironment.GO_SERVER_MODE, "development");
    setupPeriodicGC(systemEnvironment);
    assertPluginsZipExists();
    GoServer server = new GoServer();
    systemEnvironment.setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, Boolean.toString(false));
    try {
        server.startServer();

        String hostName = systemEnvironment.getListenHost();
        if (hostName == null) {
            hostName = "localhost";
        }

        System.out.println("GoCD server dashboard started on http://" + hostName + ":"
                + systemEnvironment.getServerPort());
        System.out.println("* credentials: \"admin\" / \"badger\"");
    } catch (Exception e) {
        System.err.println("Failed to start GoCD server. Exception:");
        e.printStackTrace();
    }
}