Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtilityTest.java

@Test
public void testCreateContext() throws Exception {
    File root = temp.newFolder();
    JhoveContext ctx = JhoveUtility.createContext(root);
    assertNotNull(ctx);/* www .  j a  v a  2s .  c om*/
    assertTrue(new File(root, JhoveUtility.JHOVE_CONFIG_NAME).exists());
    ctx.destroy();
    assertFalse(root.toString(), root.exists());
}

From source file:m3.classe.M3ClassLoader.java

private DataInputStream getStreamFromFolder(String name, File path) throws FileNotFoundException {
    DataInputStream dis = null;/* w  w  w  .j  av a2s  .com*/
    File file = new File(
            path.toString() + File.separator + name.replace('.', File.separatorChar) + '.' + "class");

    if (!file.exists()) {
        file = new File(
                path.toString() + File.separator + name.replace('.', File.separatorChar) + '.' + "properties");
    }
    if (file.exists()) {
        dis = new DataInputStream(new FileInputStream(file));
    }
    return dis;
}

From source file:deployer.publishers.openshift.RhcApplicationGitRepoModificationsTest.java

private void populateWithInitialFiles(Git git, File testDir) throws IOException, GitAPIException {
    log.debug("Git Repo Dir: " + git.getRepository().getDirectory().toString());
    log.debug("Test dir: " + testDir.toString());
    FileUtils.writeStringToFile(Files.resolve(testDir, "README"), "This is from the RhcApplication unit test.");
    File aDir = Files.resolve(testDir, "a-dir");
    Files.createDirectories(aDir);
    FileUtils.writeStringToFile(Files.resolve(aDir, "source.json"), "{'hello': 'world'}");
    FileUtils.writeStringToFile(Files.resolve(aDir, "AnotherFile.txt"), "A file about nothing");
    FileUtils.writeStringToFile(Files.resolve(testDir, "deployed_version.txt"), "v0.33333333333333333");
    log.info(git.add().addFilepattern(".").call().toString());
    log.info(git.commit().setAuthor("Unit Test", "unit.test@email.com").setMessage("Initial files").setAll(true)
            .call().toString());// www.j av  a 2  s .  co m
}

From source file:mSearch.filmlisten.WriteFilmlistJson.java

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {

    ZipOutputStream zipOutputStream = null;
    XZOutputStream xZOutputStream = null;
    JsonGenerator jg = null;/*from w ww  . j  av a2  s  .  c o m*/

    FileWriter fileWriter = null;
    CSVPrinter csvFilePrinter = null;
    try {
        Log.sysLog("Filme schreiben (" + listeFilme.size() + " Filme) :");
        File file = new File(datei);
        File dir = new File(file.getParent());
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                Log.errorLog(915236478, "Kann den Pfad nicht anlegen: " + dir.toString());
            }
        }
        Log.sysLog("   --> Start Schreiben nach: " + datei);

        CSVFormat csvFileFormat = CSVFormat.DEFAULT.withDelimiter(';').withQuote('\'')
                .withRecordSeparator("\n");
        fileWriter = new FileWriter(datei);
        csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);

        // Infos der Felder in der Filmliste
        csvFilePrinter.printRecord(DatenFilm.COLUMN_NAMES);

        //Filme schreiben
        DatenFilm datenFilm;
        Iterator<DatenFilm> iterator = listeFilme.iterator();
        while (iterator.hasNext()) {
            datenFilm = iterator.next();
            datenFilm.arr[DatenFilm.FILM_NEU] = Boolean.toString(datenFilm.isNew()); // damit wirs beim nchsten Programmstart noch wissen

            List<String> filmRecord = new ArrayList<String>();
            for (int i = 0; i < DatenFilm.JSON_NAMES.length; ++i) {
                int m = DatenFilm.JSON_NAMES[i];
                filmRecord.add(datenFilm.arr[m].replace("\n", "").replace("\r", ""));
            }
            csvFilePrinter.printRecord(filmRecord);
        }
        Log.sysLog("   --> geschrieben!");
    } catch (Exception ex) {
        Log.errorLog(846930145, ex, "nach: " + datei);
    } finally {
        try {
            fileWriter.flush();
            fileWriter.close();
            csvFilePrinter.close();
        } catch (Exception e) {
            Log.errorLog(732101201, e, "close stream: " + datei);
        }
    }
}

From source file:com.seniorproject.semanticweb.services.HadoopService.java

private void modifiedPig() throws IOException {
    String sReadFileName = servletContext.getRealPath("/WEB-INF/classes/PigSPARQL_v1.0/test3.pig");
    File file = new File(servletContext.getRealPath("/WEB-INF/classes/PigSPARQL_v1.0/"), "test4.pig");
    String sWriteFileName = file.toString();

    String sReplaceText = "indata = LOAD '$inputData' USING pigsparql.rdfLoader.ExNTriplesLoader(' ','expand') as (s,p,o)";
    String sReadLine = null;//from  w  w w.ja v  a  2 s.  co  m

    try {
        // FileReader reads text files in the default encoding.
        FileReader fileReader = new FileReader(sReadFileName);

        // Always wrap FileReader in BufferedReader.
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        FileWriter fileWriter = new FileWriter(sWriteFileName);

        // Always wrap FileWriter in BufferedWriter.
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

        while ((sReadLine = bufferedReader.readLine()) != null) {
            System.out.println(sReadLine);
            if (sReadLine.equals(
                    "indata = LOAD '$inputData' USING pigsparql.rdfLoader.ExNTriplesLoader(' ','expand') ;")) {
                bufferedWriter.write(
                        "indata = LOAD '$inputData' USING pigsparql.rdfLoader.ExNTriplesLoader(' ','expand') as (s,p,o);");
            } else {
                bufferedWriter.write(sReadLine);
            }
            bufferedWriter.newLine();

        }

        // Always close files.
        bufferedReader.close();
        bufferedWriter.close();
    } catch (FileNotFoundException ex) {
        System.out.println("Unable to open file '" + sReadFileName + "'");
    } catch (IOException ex) {
        System.out.println("Error reading file '" + sReadFileName + "'");
        // Or we could just do this: 
        // ex.printStackTrace();
    }
}

From source file:cz.cas.lib.proarc.common.object.emods.BornDigitalDisseminationHandler.java

private boolean isPdf(File f) throws DigitalObjectException {
    try {//  ww  w . java2 s . c  om
        return InputUtils.isPdf(f);
    } catch (IOException ex) {
        throw new DigitalObjectException(objHandler.getFedoraObject().getPid(), null, dsId, f.toString(), ex);
    }
}

From source file:dk.statsbiblioteket.util.Files.java

/**
 * Copies a file (not a folder).//from   w w  w .  ja va  2s  . co  m
 *
 * @param source      the file to copy.
 * @param destination where to copy the file to. If this is an existing
 *                    directory, {@code source} will be copied into it,
 *                    otherwise {@code source} will copied to this file.
 * @param overwrite   whether or not to overwrite if the destination
 *                    already exists.
 * @throws IOException                thrown if there was an error writing to the
 *                                    destination file, or if the input file doidn't exist
 *                                    or if the source was a directory.
 * @throws FileNotFoundException      thrown if the source file did not exist.
 * @throws FileAlreadyExistsException if there's already a file at
 *                                    {@code destination} and {@code overwrite} was
 *                                    {@code false}.
 */
private static void copyFile(File source, File destination, boolean overwrite) throws IOException {
    log.trace("copyFile(" + source + ", " + destination + ", " + overwrite + ") called");
    source = source.getAbsoluteFile();
    destination = destination.getAbsoluteFile();
    if (!source.exists()) {
        throw new FileNotFoundException("The source '" + source + "' does not exist");
    }
    if (destination.isDirectory()) {
        throw new IOException("The destination '" + destination + "' is a directory");
    }

    if (destination.exists() && destination.isDirectory()) {
        destination = new File(destination, source.getName());
    }

    if (!overwrite && destination.exists()) {
        throw new FileAlreadyExistsException(destination.toString());
    }

    // BufferedInputStream is not used, as it chokes > 2GB
    InputStream in = new FileInputStream(source);
    OutputStream out = new FileOutputStream(destination);

    try {
        byte[] buf = new byte[2028];
        int count = 0;
        while ((count = in.read(buf)) != -1) {
            out.write(buf, 0, count);
        }
    } finally {
        in.close();
        out.close();
    }
    destination.setExecutable(source.canExecute());
}

From source file:org.powertac.producer.ProducerService.java

/**
 * This function de-serializes the producers into objects and returns a list
 * with the resulting objects/*from w  ww.  j av a2 s. com*/
 * 
 * @return
 * @throws IOException
 */
protected List<Producer> loadProducers() throws IOException {
    List<Producer> producers = new ArrayList<Producer>();

    // filters the xml files
    FileFilter filter = new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            String name = pathname.toString().toLowerCase();
            if (pathname.isFile() && name.endsWith(".xml")) {
                return true;
            }
            return false;
        }
    };

    // Help xstream understand the xml files
    XStream xstream = new XStream();
    xstream.processAnnotations(SteamPlant.class);
    xstream.processAnnotations(Dam.class);
    xstream.processAnnotations(RunOfRiver.class);
    xstream.processAnnotations(HydroBase.class);
    xstream.processAnnotations(WindFarm.class);
    xstream.processAnnotations(WindTurbine.class);
    xstream.processAnnotations(SolarFarm.class);
    xstream.processAnnotations(PvPanel.class);
    xstream.processAnnotations(Producer.class);

    // this loads the default producers
    if (producerFileFolder == null) {
        for (String name : defaultProducers) {
            InputStream stream = ProducerService.class.getResourceAsStream(name);
            Producer producer = (Producer) xstream.fromXML(stream);
            producers.add(producer);
            stream.close();
        }
        return producers;
    }

    File confFolder = new File(this.producerFileFolder);
    if (!confFolder.isDirectory() || !confFolder.exists()) {
        // folder is wrong return an empty array
        log.error("The supplied configuration path was invalid.");
    } else {
        // iterate over all the files and dererialize them
        for (File conf : confFolder.listFiles(filter)) {
            String name = conf.toString().toLowerCase();
            if (name.contains("steam") || name.contains("dam") || name.contains("river")
                    || name.contains("solar") || name.contains("wind")) {
                Producer producer = (Producer) xstream.fromXML(conf);
                producers.add(producer);
            }
        }
    }
    return producers;
}

From source file:com.collective.celos.WorkflowConfigurationParser.java

public void importDefaultsIntoScope(String label, Global scope) throws IOException {
    File defaultsFile = new File(defaultsDir, label + "." + WORKFLOW_FILE_EXTENSION);
    LOGGER.info("Loading defaults: " + defaultsFile);
    FileReader fileReader = new FileReader(defaultsFile);
    String fileName = defaultsFile.toString();
    jsConfigParser.evaluateReader(scope, fileReader, fileName);
}

From source file:com.symbian.driver.plugins.ftptelnet.test.FtpTransferTest.java

public final void testPwd() {
    FtpTransfer lSession = FtpTransfer.getInstance("tcp:192.168.0.3:21");
    assertTrue(lSession.mkdir(iDeepRemoteFolder));
    lSession.cd(iRemoteFolder);/*w  ww .j  ava 2 s .c  om*/
    File lFile = lSession.pwd();
    assertNotNull(lFile);
    System.out.println("PWD returned:" + lFile.toString());
    assertEquals(iRemoteFolder, lFile);
}