List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:gridool.db.partitioning.monetdb.MonetDBCopyIntoOperation.java
private static File prepareLoadFile(final String tableName, final byte[] data) { DbCollection rootColl = DbCollection.getRootCollection(); File colDir = rootColl.getDirectory(); if (!colDir.exists()) { throw new IllegalStateException("Database directory not found: " + colDir.getAbsoluteFile()); }/* w w w . j av a2 s . c o m*/ final File loadFile; final FileOutputStream fos; try { loadFile = File.createTempFile(tableName, ".csv", colDir); fos = new FileOutputStream(loadFile); } catch (IOException e) { throw new IllegalStateException("Failed to create a load file", e); } try { FastBufferedOutputStream bos = new FastBufferedOutputStream(fos, 8192); bos.write(data, 0, data.length); bos.flush(); bos.close(); } catch (IOException e) { try { fos.close(); } catch (IOException ioe) { LOG.debug(ioe); } throw new IllegalStateException("Failed to write data into file: " + loadFile.getAbsolutePath(), e); } return loadFile; }
From source file:com.sap.prd.mobile.ios.mios.FileUtils.java
public static boolean isChild(File parent, File child) { return isChild(split(parent.getAbsoluteFile()), split(child.getAbsoluteFile())); }
From source file:de.pksoftware.springstrap.sapi.util.WebappZipper.java
/** * Unzip it//from w ww . j a v a 2 s .c o m * @param zipFile input zip file * @param output zip file output folder */ public static void unzip(String zipFile, String outputFolder) { logger.info("Unzipping {} into {}.", zipFile, outputFolder); byte[] buffer = new byte[1024]; try { //get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { ze = zis.getNextEntry(); continue; } String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); logger.debug("Unzipping: {}", newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); logger.debug("Unzipping {} completed.", zipFile); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:edu.usc.polar.NLTKRest.java
public static void dir(String path, String[] args) { try {//w w w . j av a2 s . c o m File root = new File(path); if (root.isFile()) { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_" + jsonCount + ".json"); if (jsonFile != null) { jsonFile.write("{\"NER_NLTKRest\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); // System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!root.getName().equals((".DS_Store"))) { ApacheNLTKRest(root.getAbsolutePath(), args); counter++; } } else { File[] list = root.listFiles(); if (list == null) { return; } for (File f : list) { if (f.isDirectory()) { dir(f.getAbsolutePath(), args); System.out.println("Dir:" + f.getAbsoluteFile()); } else { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_" + jsonCount + ".json"); // System.out.print("check"+jsonArray.toJSONString()); if (jsonFile != null) { jsonFile.write("{\"NER_NLTKRest\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!f.getName().equals((".DS_Store"))) { ApacheNLTKRest(f.getAbsolutePath(), args); counter++; // add json } } } } } catch (Exception e) { System.err.print(e.toString()); } }
From source file:de.blizzy.backup.Utils.java
public static File toCanonicalFile(File file) { try {//from w ww . j a v a2 s . c om return file.getCanonicalFile(); } catch (IOException e) { // ignore } return file.getAbsoluteFile(); }
From source file:de.monticore.io.paths.IterablePath.java
/** * Creates a new {@link IterablePath} based on the supplied input {@link File} . The file * extension of the input {@link File} must be one of the supplied file extensions otherwise the * resulting {@link IterablePath} will be empty. * /* w w w . jav a 2 s . c o m*/ * @param file * @param extensions * @return */ public static IterablePath from(File file, Set<String> extensions) { return from(Lists.newArrayList(file.getAbsoluteFile()), extensions); }
From source file:edu.usc.polar.OpenNLP.java
public static void dir(String path, String[] args) { try {//from w w w. j a v a 2s .c om File root = new File(path); if (root.isFile()) { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_" + jsonCount + ".json"); if (jsonFile != null) { jsonFile.write("{\"NER_OpenNLP\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!root.getName().equals((".DS_Store"))) { ApacheOpenNLP(root.getAbsolutePath(), args); counter++; } } else { File[] list = root.listFiles(); if (list == null) { return; } for (File f : list) { if (f.isDirectory()) { dir(f.getAbsolutePath(), args); System.out.println("Dir:" + f.getAbsoluteFile()); } else { if (counter >= 1000 || file == null) { counter = 0; jsonCount++; file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\OpenNLP\\NER_" + jsonCount + ".json"); // System.out.print("check"+jsonArray.toJSONString()); if (jsonFile != null) { jsonFile.write("{\"NER_OpenNLP\":"); jsonFile.write(jsonArray.toJSONString()); jsonFile.write("}"); System.out.println(jsonArray.toJSONString()); jsonFile.close(); } jsonFile = new FileWriter(file); jsonArray = new JSONArray(); } if (!f.getName().equals((".DS_Store"))) { ApacheOpenNLP(f.getAbsolutePath(), args); counter++; // add json } } } } } catch (Exception e) { e.toString(); } }
From source file:edu.kit.dama.util.ZipUtils.java
/** * Unzip file in 'actual' directory and delete zip file. * * @param fSourceZip zip file to extract. * @param delete delete source file or not. *//* ww w . j a va 2s . c o m*/ public static void unzip(File fSourceZip, boolean delete) { File zipPath = fSourceZip.getAbsoluteFile().getParentFile(); unzip(fSourceZip, zipPath, delete); }
From source file:it.geosolutions.sfs.web.Start.java
private static void assureSelfSignedServerCertificate(String hostname, File keyStoreFile, String password) throws Exception { KeyStore privateKS = KeyStore.getInstance("JKS"); if (keyStoreFile.exists()) { FileInputStream fis = new FileInputStream(keyStoreFile); privateKS.load(fis, password.toCharArray()); if (keyStoreContainsCertificate(privateKS, hostname)) return; } else {//from www . j a v a2 s .co m privateKS.load(null); } // create a RSA key pair generator using 1024 bits KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(1024); KeyPair KPair = keyPairGenerator.generateKeyPair(); // cerate a X509 certifacte generator // X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); // set validity to 10 years, issuer and subject are equal --> self singed certificate int random = new SecureRandom().nextInt(); if (random < 0) random *= -1; // v3CertGen.setSerialNumber(BigInteger.valueOf(random)); // v3CertGen.setIssuerDN(new X509Principal("CN=" + hostname + ", OU=None, O=None L=None, C=None")); // v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30)); // v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10))); // v3CertGen.setSubjectDN(new X509Principal("CN=" + hostname + ", OU=None, O=None L=None, C=None")); // // v3CertGen.setPublicKey(KPair.getPublic()); // v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption"); // // X509Certificate PKCertificate = v3CertGen.generateX509Certificate(KPair.getPrivate()); // // store the certificate containing the public key,this file is needed // to import the public key in other key store. File certFile = new File(keyStoreFile.getParentFile(), hostname + ".cert"); FileOutputStream fos = new FileOutputStream(certFile.getAbsoluteFile()); // fos.write(PKCertificate.getEncoded()); fos.close(); // privateKS.setKeyEntry(hostname+".key", KPair.getPrivate(), // password.toCharArray(), // new java.security.cert.Certificate[]{PKCertificate}); // // privateKS.setCertificateEntry(hostname+".cert",PKCertificate); privateKS.store(new FileOutputStream(keyStoreFile), password.toCharArray()); }
From source file:com.qmetry.qaf.automation.util.FileUtil.java
public static String getRelativePath(File fileOrFolder, File baseFolder) { if (!baseFolder.isDirectory()) baseFolder = baseFolder.getAbsoluteFile().getParentFile(); return baseFolder.toURI().relativize(fileOrFolder.toURI()).getPath(); }