List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:com.dchq.docker.volume.driver.adaptor.LocalVolumeAdaptorImpl.java
@Override public MountResponse mount(MountRequest request) { MountResponse response = new MountResponse(); try {//w ww . j a va 2 s .c o m File file = new File(new File(TMP_LOC), request.getName()); if (file.isDirectory()) { response.setMountpoint(file.getAbsolutePath()); } logger.info("Mounted Volume [{}] on path [{}]", file.getName(), file.getAbsoluteFile()); } catch (Exception e) { logger.warn(e.getLocalizedMessage(), e); response.setErr(e.getLocalizedMessage()); } return response; }
From source file:com.splout.db.dnode.TestFetcher.java
@Test public void testFileFetching() throws IOException, URISyntaxException, InterruptedException { SploutConfiguration testConfig = SploutConfiguration.getTestConfig(); testConfig.setProperty(FetcherProperties.TEMP_DIR, "tmp-dir-" + TestFetcher.class.getName()); Fetcher fetcher = new Fetcher(testConfig); File file = new File("tmp-" + TestFetcher.class.getName()); Files.write("This is what happens when you don't know what to write".getBytes(), file); File f = fetcher.fetch(file.getAbsoluteFile().toURI().toString()); assertTrue(f.exists());// w w w . jav a2s.c om assertTrue(f.isDirectory()); File file2 = new File(f, "tmp-" + TestFetcher.class.getName()); assertTrue(file.exists()); assertEquals("This is what happens when you don't know what to write", Files.toString(file2, Charset.defaultCharset())); file.delete(); FileUtils.deleteDirectory(f); }
From source file:icevaluation.GetWikiURL.java
private void writeKeyInfoBack() { try {// w w w . ja v a 2s . com File file = new File("data/apiKeySettings.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); for (String key : keyMap.keySet()) { bw.write(key + " " + keyMap.get(key) + "\n"); } bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } }
From source file:adams.core.io.TarUtils.java
/** * Decompresses the files in a tar file. Files can be filtered based on their * filename, using a regular expression (the matching sense can be inverted). * * @param input the tar file to decompress * @param outputDir the directory where to store the extracted files * @param createDirs whether to re-create the directory structure from the * tar file//from w w w . j av a2 s . c o m * @param match the regular expression that the files are matched against * @param invertMatch whether to invert the matching sense * @param bufferSize the buffer size to use * @param errors for storing potential errors * @return the successfully extracted files */ public static List<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize, StringBuilder errors) { List<File> result; FileInputStream fis; TarArchiveInputStream archive; TarArchiveEntry entry; File outFile; String outName; byte[] buffer; BufferedOutputStream out; FileOutputStream fos; int len; String error; long size; long read; result = new ArrayList<>(); archive = null; fis = null; fos = null; try { // decompress archive buffer = new byte[bufferSize]; fis = new FileInputStream(input.getAbsoluteFile()); archive = openArchiveForReading(input, fis); while ((entry = archive.getNextTarEntry()) != null) { if (entry.isDirectory() && !createDirs) continue; // does name match? if (!match.isMatchAll() && !match.isEmpty()) { if (invertMatch && match.isMatch(entry.getName())) continue; else if (!invertMatch && !match.isMatch(entry.getName())) continue; } // extract if (entry.isDirectory() && createDirs) { outFile = new File(outputDir.getAbsolutePath() + File.separator + entry.getName()); if (!outFile.mkdirs()) { error = "Failed to create directory '" + outFile.getAbsolutePath() + "'!"; System.err.println(error); errors.append(error + "\n"); } } else { out = null; outName = null; try { // assemble output name outName = outputDir.getAbsolutePath() + File.separator; if (createDirs) outName += entry.getName(); else outName += new File(entry.getName()).getName(); // create directory, if necessary outFile = new File(outName).getParentFile(); if (!outFile.exists()) { if (!outFile.mkdirs()) { error = "Failed to create directory '" + outFile.getAbsolutePath() + "', " + "skipping extraction of '" + outName + "'!"; System.err.println(error); errors.append(error + "\n"); continue; } } // extract data fos = new FileOutputStream(outName); out = new BufferedOutputStream(fos, bufferSize); size = entry.getSize(); read = 0; while (read < size) { len = archive.read(buffer); read += len; out.write(buffer, 0, len); } result.add(new File(outName)); } catch (Exception e) { error = "Error extracting '" + entry.getName() + "' to '" + outName + "': " + e; System.err.println(error); errors.append(error + "\n"); } finally { FileUtils.closeQuietly(out); FileUtils.closeQuietly(fos); } } } } catch (Exception e) { e.printStackTrace(); errors.append("Error occurred: " + e + "\n"); } finally { FileUtils.closeQuietly(fis); if (archive != null) { try { archive.close(); } catch (Exception e) { // ignored } } } return result; }
From source file:com.goodformobile.build.mobile.RIMPackageMojoTest.java
@Test public void testExecuteOnBasicApplication() throws Exception { File projectDirectory = getRelativeFile("projects/maven-test-app-preverified/pom.xml").getParentFile(); File workProjectDirectory = setupCleanCopyOfProject(projectDirectory); RIMPackageMojo mojo = setupMojo();//from w w w .jav a 2 s. c o m MavenProject project = getProject(mojo); setupProject(workProjectDirectory, project); mojo.execute(); // Ensure a jad is generated. File targetDirectory = new File(workProjectDirectory, "target"); File expectedJad = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "maven_test_app.jad"); assertTrue("Unable to find generated jad: " + expectedJad.getAbsolutePath(), expectedJad.exists()); // Ensure a cod file is generated. File expectedCod = new File(targetDirectory.getAbsoluteFile() + File.separator + "deliverables" + File.separator + "maven_test_app.cod"); assertTrue("Unable to find generated cod: " + expectedCod.getAbsolutePath(), expectedCod.exists()); }
From source file:de.fuberlin.wiwiss.marbles.MarblesServlet.java
/** * Reads data from a URL in a given syntax into a Sesame repository; * supports {@link ParamReader}/* w w w . j a v a 2 s . c o m*/ * * @param store Add RDF to this <code>LocalRepository</code> * @param url The <code>String</code> location of the data * @param syntax The <code>String</code> syntax of the data * @throws Exception For any problems encountered during read of data from the URL */ public static void loadTriples(Repository store, File file, HashMap<String, String> parameters, Resource... context) throws Exception { RDFFormat format = null; if (file.getName().endsWith(".nt")) format = RDFFormat.NTRIPLES; else if (file.getName().endsWith(".rdf")) format = RDFFormat.RDFXML; else if (file.getName().endsWith(".n3")) format = RDFFormat.N3; else if (file.getName().endsWith(".ttl")) format = RDFFormat.TURTLE; else throw new ServletException("No RDF format known for " + file.getName()); String baseURI = "file://" + file.getAbsoluteFile(); RepositoryConnection conn = store.getConnection(); BufferedReader fileReader = new BufferedReader(new FileReader(file)); if (parameters != null) { ParamReader paramReader = new ParamReader(parameters, fileReader); conn.add(paramReader, baseURI, format, context); } else conn.add(fileReader, baseURI, format, context); conn.commit(); conn.close(); }
From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java
public static File sharedContextRoot(Properties configProperties, ServletContext context, Logger log) { File sharedContentRoot = null; if (configProperties.containsKey(BASE_PATH_ENV)) { sharedContentRoot = new File(configProperties.getProperty(BASE_PATH_ENV)); if (!sharedContentRoot.exists() || !sharedContentRoot.canRead() || !sharedContentRoot.canWrite()) { if (!sharedContentRoot.mkdirs()) { sharedContentRoot = null; }/*www .jav a 2s.c o m*/ } } if (sharedContentRoot == null) { log.warn("Could not access cadmium content root. Using the tempdir."); sharedContentRoot = (File) context.getAttribute("javax.servlet.context.tempdir"); configProperties.setProperty(BASE_PATH_ENV, sharedContentRoot.getAbsoluteFile().getAbsolutePath()); } return sharedContentRoot; }
From source file:io.confluent.connect.jdbc.EmbeddedDerby.java
/** * Drops the database by deleting it's files from disk. This assumes the working directory * isn't changing so the database files can be found relative to the current working directory. *///from w w w. j a v a 2 s. c o m public void dropDatabase() throws IOException { File dbDir = new File(getRawName()); log.debug("Dropping database {} by removing directory {}", name, dbDir.getAbsoluteFile()); FileUtils.deleteDirectory(dbDir); }
From source file:com.github.nethad.clustermeister.integration.JPPFTestNode.java
private void untar(File tarFile) throws IOException { logger.info("Untar {}.", tarFile.getAbsolutePath()); TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new FileInputStream(tarFile)); try {//w w w . ja v a 2 s . c o m ArchiveEntry tarEntry = tarArchiveInputStream.getNextEntry(); while (tarEntry != null) { File destPath = new File(libDir, tarEntry.getName()); logger.info("Unpacking {}.", destPath.getAbsoluteFile()); if (!tarEntry.isDirectory()) { FileOutputStream fout = new FileOutputStream(destPath); final byte[] buffer = new byte[8192]; int n = 0; while (-1 != (n = tarArchiveInputStream.read(buffer))) { fout.write(buffer, 0, n); } fout.close(); } else { destPath.mkdir(); } tarEntry = tarArchiveInputStream.getNextEntry(); } } finally { tarArchiveInputStream.close(); } }