Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.meltmedia.cadmium.core.history.HistoryManagerTest.java

@Before
public void setupForTest() throws Exception {
    File testDir = new File("./target/history-test");
    testDirectory = testDir.getAbsoluteFile().getAbsolutePath();

    if (!testDir.exists()) {
        testDir.mkdirs();/*from w  w w  .java  2s . co  m*/
    }

    historyFile = new File(testDir, HistoryManager.HISTORY_FILE_NAME);

    if (!historyFile.exists() || historyFile.canWrite()) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(historyFile, false);
            writer.write(INIT_HISTORY_CONTENT);
            writer.flush();
        } catch (Exception e) {
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }

    manager = new HistoryManager(testDirectory, Executors.newSingleThreadExecutor(), mock(EventQueue.class));
}

From source file:com.moss.veracity.core.filemonitor.FileMonitor.java

private FileMonitor(File file, long interval) {
    this.file = file.getAbsoluteFile();

    reset();/*from w w w .j a  v a  2s . c  o m*/

    timer = new Timer(true);
    timer.scheduleAtFixedRate(new MonitorTask(), 0, interval);
}

From source file:egovframework.com.utl.wed.filter.DefaultFileSaveManager.java

@Override
public String saveFile(FileItem fileItem, String imageBaseDir, String imageDomain) {
    String originalFileName = FilenameUtils.getName(fileItem.getName());
    String relUrl;/*  w  ww.  ja  v  a2  s.  c  o  m*/
    // filename
    String subDir = File.separator + DirectoryPathManager
            .getDirectoryPathByDateType(DirectoryPathManager.DIR_DATE_TYPE.DATE_POLICY_YYYY_MM);
    String fileName = RandomStringUtils.randomAlphanumeric(20) + "."
            + StringUtils.lowerCase(StringUtils.substringAfterLast(originalFileName, "."));

    File newFile = new File(imageBaseDir + subDir + fileName);
    File fileToSave = DirectoryPathManager.getUniqueFile(newFile.getAbsoluteFile());

    try {
        FileUtils.writeByteArrayToFile(fileToSave, fileItem.get());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String savedFileName = FilenameUtils.getName(fileToSave.getAbsolutePath());
    relUrl = StringUtils.replace(subDir, "\\", "/") + savedFileName;

    return imageDomain + relUrl;
}

From source file:co.rsk.core.NetworkStateExporter.java

public boolean exportStatus(String outputFile) {
    Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());

    File dumpFile = new File(outputFile);

    try (FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw)) {
        JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
        ObjectNode mainNode = jsonFactory.objectNode();
        for (ByteArrayWrapper address : frozenRepository.getAccountsKeys()) {
            if (!address.equals(new ByteArrayWrapper(ZERO_BYTE_ARRAY))) {
                mainNode.set(Hex.toHexString(address.getData()),
                        createAccountNode(mainNode, address.getData(), frozenRepository));
            }//w w  w.  ja va2 s. c om
        }
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        bw.write(writer.writeValueAsString(mainNode));
        return true;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        panicProcessor.panic("dumpstate", e.getMessage());
        return false;
    }
}

From source file:com.aurel.track.teamgeist.TeamgeistServicesTest.java

/**
 * This method returns Teamgeist source path till Services.cpp.
 * The source base directory is provided by: buildwin or buildux properties (Windows or mac)
 * @return//from ww  w .j  a  va  2  s. com
 */
private String getSrcPath() {
    String propertiesFileName = null;
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        propertiesFileName = "buildwin.properties";
    } else if (System.getProperty("os.name").toLowerCase().contains("mac")
            || System.getProperty("os.name").toLowerCase().contains("linux")) {
        propertiesFileName = "buildux.properties";
    } else {
        return null;
    }
    final String COM_TRACKPLUS_RELATIVE_PATH = "/com.trackplus/" + propertiesFileName;
    File file = new java.io.File("");
    String propertiesPath = file.getAbsoluteFile().getParentFile().getAbsolutePath();
    String srcPath = null;
    if (propertiesPath.contains("\\")) {
        propertiesPath = propertiesPath.replace("\\", "/");
        if (propertiesPath.lastIndexOf("/") == propertiesPath.length() - 1) {
            propertiesPath = propertiesPath.substring(0, propertiesPath.length() - 1);
        }
    }
    propertiesPath += COM_TRACKPLUS_RELATIVE_PATH;
    try {
        final String RELATIVE_PART_OF_PATH = "/services/Services.cpp";
        System.err.println(propertiesPath);
        InputStream input = new FileInputStream(propertiesPath);
        Properties prop = new Properties();
        prop.load(input);
        srcPath = prop.get("teamgeist.srcAbsolutePath").toString();
        srcPath = srcPath.replace("\\", "/");
        if (srcPath.lastIndexOf("/") == srcPath.length() - 1) {
            srcPath = srcPath.substring(0, srcPath.length() - 1);
        }
        srcPath += RELATIVE_PART_OF_PATH;
    } catch (Exception ex) {
        LOGGER.error(ExceptionUtils.getStackTrace(ex));
    }
    System.out.println("Using Teamgeist source from " + srcPath);
    return srcPath;
}

From source file:com.marcolotz.lung.debug.InputTester.java

/***
 * Method used for local testing the record reader and the Input format. It
 * generates an input split from the local file system file.
 * //from w  ww .  j av a  2s  .  c om
 * @param filePath
 */
public void localTest(String filePath) {
    DICOM image;
    Configuration testConf = new Configuration(false);

    /* Reads the local file system */
    testConf.set("fs.default.name", "file:///");

    File testFile = new File(filePath);

    Path path = new Path(testFile.getAbsoluteFile().toURI());
    FileSplit split = new FileSplit(path, 0, testFile.length(), null);

    InputFormat<NullWritable, BytesWritable> inputFormat = ReflectionUtils
            .newInstance(WholeFileInputFormat.class, testConf);
    TaskAttemptContext context = new TaskAttemptContextImpl(testConf, new TaskAttemptID());

    try {
        RecordReader<NullWritable, BytesWritable> reader = inputFormat.createRecordReader(split, context);
        while (reader.nextKeyValue()) {
            /* get the bytes array */
            BytesWritable inputBytesWritable = (BytesWritable) reader.getCurrentValue();
            byte[] inputContent = inputBytesWritable.getBytes();

            /* Check for Correct value */
            // generateLocalOutput("path/to/output");

            InputStream is = new ByteArrayInputStream(inputContent);

            image = new DICOM(is);
            image.run("Dicom Test");

            /* Prints the bytes as an ImagePlus image */
            ImageViewer debug = new ImageViewer();
            debug.setImage(image);
        }
    } catch (Exception e) {

    }
}

From source file:DIA_Umpire_To_Skyline.FileThread.java

private void ChangeScanTitlePepXML() throws FileNotFoundException, IOException {
    File fileEntry = new File(FilenameUtils.getFullPath(mzXMLFile));
    String basename = FilenameUtils.getBaseName(mzXMLFile);
    for (File file : fileEntry.listFiles()) {
        if (file.isFile() && file.getAbsoluteFile().toString().toLowerCase().endsWith("pep.xml")) {
            String pepxmlbase = file.getName().split("\\.")[0];
            if (pepxmlbase.equals(basename + "_Q1") || pepxmlbase.equals(basename + "_Q2")
                    || pepxmlbase.equals(basename + "_Q3")) {
                BufferedReader reader = new BufferedReader(new FileReader(file));
                String outputname = file.getName().replace("_Q", ".ForLibQ");
                Logger.getRootLogger()
                        .info("Writing new pepXML files and correct the scan titles: " + outputname);
                FileWriter writer = new FileWriter(FilenameUtils.getFullPath(mzXMLFile)
                        + FilenameUtils.getBaseName(mzXMLFile) + "_Skyline/" + outputname);
                String line = "";
                while ((line = reader.readLine()) != null) {
                    writer.write(line.replaceAll(basename + "_Q", basename + ".ForLibQ") + "\n");
                }// ww w .j av  a 2  s.c  o  m
                writer.close();
            }
        }
    }
}

From source file:ch.unibas.fittingwizard.application.xyz.XyzFileParser.java

private XyzFileParser(File file) {
    //        logger.setLevel(Level.INFO);
    logger.info(String.format("Initializing parser for file %s", file.getAbsoluteFile()));
    this.file = file;
}

From source file:com.github.riccardove.easyjasub.EasyJaSubInputFromCommand.java

private static void checkOutputFile(String fileName, File file) throws EasyJaSubException {
    if (file.exists()) {
        if (file.isDirectory()) {
            throw new EasyJaSubException("Invalid output file, " + fileName + " is a directory");
        }/*  w  ww  . j  a v  a2  s .  c  om*/
        return;
    }
    File directory = file.getAbsoluteFile();
    do {
        directory = directory.getParentFile();
    } while (directory != null && !directory.exists());
    if (directory != null && !directory.canWrite()) {
        throw new EasyJaSubException(
                "Can not write on " + directory.getAbsolutePath() + " to create " + fileName);
    }
}

From source file:net.leegorous.jsc.TestJavaScriptDocument.java

public void testReadFile() throws Exception {
    File file = new File(getFileName("/scripts/a.js"));
    JavaScriptDocument.readFile(file);/*from  w ww  .  jav a  2  s.com*/
    log.debug(file.getAbsoluteFile() + (file.exists() ? "" : "does not") + " exist");
}