List of usage examples for java.io File getAbsoluteFile
public File getAbsoluteFile()
From source file:com.skcraft.launcher.builder.PackageBuilder.java
public void writeManifest(@NonNull File path) throws IOException { manifest.setFeatures(applicator.getFeaturesInUse()); VersionManifest versionManifest = manifest.getVersionManifest(); if (versionManifest != null) { versionManifest.setId(manifest.getGameVersion()); }/*from w w w.ja va2 s . c o m*/ validateManifest(); path.getAbsoluteFile().getParentFile().mkdirs(); writer.writeValue(path, manifest); }
From source file:br.com.ifpb.bdnc.projeto.geo.system.MultipartData.java
public boolean saveImage(String path, FileItemStream item, String nameToSave) { try {//w w w .ja v a 2 s. co m File f = new File(path + File.separator + folder); File parent = new File(f.getParent()); if (!parent.exists()) parent.mkdir(); if (!f.exists()) f.mkdir(); System.out.println(f.getAbsolutePath()); File savedFile = new File(f.getAbsoluteFile() + File.separator + nameToSave); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:net.sf.infrared.collector.impl.persistence.InProcessDataSource.java
boolean copy(String src, File dest) { // @TODO replace this with Commons FileUtils if (dest.exists()) { if (log.isDebugEnabled()) { log.debug(dest.getAbsoluteFile() + " exists"); }/*w ww . ja v a2s.c om*/ return false; } else { if (log.isDebugEnabled()) { log.debug(dest.getAbsoluteFile() + " doesn't exists"); } } URL srcUrl = null; try { srcUrl = Thread.currentThread().getContextClassLoader().getResource(src); } catch (Throwable th) { log.error("Failed to find default in-process DB schema", th); return false; } if (srcUrl == null) { log.error("Failed to find default in-process DB schema"); return false; } InputStream srcStream = null; byte[] bytes = null; try { srcStream = srcUrl.openStream(); bytes = new byte[srcStream.available()]; srcStream.read(bytes); } catch (IOException e) { log.fatal("Failed to read in-process DB schema from " + srcUrl, e); return false; } finally { try { if (srcStream != null) { srcStream.close(); } } catch (IOException ignored) { } } FileOutputStream destStream = null; try { if (!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); } dest.createNewFile(); destStream = new FileOutputStream(dest); destStream.write(bytes); if (log.isDebugEnabled()) { log.debug("Create new in-process database at " + getDbPath()); } return true; } catch (IOException e) { log.fatal("Failed to create file " + dest, e); return false; } finally { try { if (destStream != null) { destStream.close(); } } catch (IOException ignored) { } } }
From source file:com.dotcms.publisher.myTest.PushPublisher.java
/** * Compress (tar.gz) the input files to the output file * * @param files The files to compress/*from w w w. ja va 2 s . c om*/ * @param output The resulting output file (should end in .tar.gz) * @param bundleRoot * @throws IOException */ private void compressFiles(Collection<File> files, File output, String bundleRoot) throws IOException { Logger.info(this.getClass(), "Compressing " + files.size() + " to " + output.getAbsoluteFile()); // Create the output stream for the output file FileOutputStream fos = new FileOutputStream(output); // Wrap the output file stream in streams that will tar and gzip everything TarArchiveOutputStream taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(fos))); // TAR originally didn't support long file names, so enable the support for it taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); // Get to putting all the files in the compressed output file for (File f : files) { addFilesToCompression(taos, f, ".", bundleRoot); } // Close everything up taos.close(); fos.close(); }
From source file:com.frostwire.android.gui.httpserver.DesktopUploadHandler.java
private boolean readFile(InputStream is, String filePath, String token) { String fileName = FilenameUtils.getName(filePath); FileOutputStream fos = null;//from w w w. ja v a2s . c o m File file = null; DesktopTransfer transfer = null; DesktopTransferItem transferItem = null; try { file = new File(SystemUtils.getTempDirectory(), fileName); fos = new FileOutputStream(file); DesktopUploadRequest dur = sessionManager.getDUR(token); FileDescriptor fd = findFD(dur, filePath); transfer = TransferManager.instance().desktopTransfer(dur, fd); transferItem = transfer.getItem(fd); byte[] buffer = new byte[4 * 1024]; int n; while ((n = is.read(buffer, 0, buffer.length)) != -1) { fos.write(buffer, 0, n); if (transfer.isCanceled()) { sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.REJECTED); file.delete(); fos.close(); return false; } else { transferItem.addBytesTransferred(n); sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.UPLOADING); } } sessionManager.updateDURStatus(token, DesktopUploadRequestStatus.ACCEPTED); File finalFile = new File(SystemUtils.getDesktopFilesirectory(), file.getName()); if (file.renameTo(finalFile)) { Librarian.instance().scan(finalFile.getAbsoluteFile()); return true; } else { file.delete(); } } catch (Throwable e) { Log.e(TAG, String.format("Error saving file: fileName=%s, token=%s", fileName, token), e); if (file != null) { file.delete(); } if (transferItem != null) { transferItem.setFailed(); } } finally { if (fos != null) { try { fos.close(); } catch (Throwable e) { // ignore } } try { is.close(); } catch (Throwable e) { // ignore } } return false; }
From source file:net.ontopia.infoset.content.FileContentStore.java
public FileContentStore(File store_root) throws ContentStoreException { if (!store_root.canWrite()) throw new ContentStoreException( "Content store root directory '" + store_root.getAbsoluteFile() + "' not writable."); // FIXME: should use java.nio.FileLock to ensure that only this // JVM accesses this directory. should also use some mechanism to // ensure that we are the only FileContentStore on this directory // within this JVM. ///*from ww w.j a v a2 s.c o m*/ // UPDATE: key file is now being protected using file locks. Still // need to add locks when deleting entries. // set up members this.store_root = store_root; this.files_per_directory = FILES_PER_DIRECTORY; this.open = true; this.key_file = new File(store_root, "keyfile.txt"); // initialize allocateNewBlock(); }
From source file:com.frostwire.gui.library.DownloadTask.java
@Override public void run() { if (!isRunning()) { return;/* w ww.ja v a2 s. c o m*/ } File lastFile = null; try { setProgress(0); if (!savePath.exists()) { savePath.mkdirs(); } long totalBytes = getTotalBytes(); long totalWritten = 0; for (int i = 0; i < fds.length; i++) { if (!isRunning()) { return; } currentFD = fds[i]; GUIMediator.safeInvokeLater(new Runnable() { public void run() { String status = String.format("%s from %s - %s", I18n.tr("Downloading"), device.getName(), currentFD.title); LibraryMediator.instance().getLibrarySearch().pushStatus(status); } }); URL url = new URL(device.getDownloadURL(currentFD)); InputStream is = null; OutputStream fos = null; try { is = url.openStream(); String filename = OSUtils.escapeFilename(FilenameUtils.getName(currentFD.filePath)); File file = buildFile(savePath, filename); Path incompleteFile = buildIncompleteFile(file).toPath(); lastFile = file.getAbsoluteFile(); fos = Files.newOutputStream(incompleteFile, StandardOpenOption.CREATE);// new FileOutputStream(incompleteFile); byte[] buffer = new byte[4 * 1024]; int n = 0; while ((n = is.read(buffer, 0, buffer.length)) != -1) { if (!isRunning()) { return; } fos.write(buffer, 0, n); fos.flush(); totalWritten += n; setProgress((int) ((totalWritten * 100) / totalBytes)); if (getProgress() % 5 == 0) { GUIMediator.safeInvokeLater(new Runnable() { public void run() { String status = String.format("%d%% %s from %s - %s", getProgress(), I18n.tr("Downloading"), device.getName(), currentFD.title); LibraryMediator.instance().getLibrarySearch().pushStatus(status); } }); } //System.out.println("Progress: " + getProgress() + " Total Written: " + totalWritten + " Total Bytes: " + totalBytes); } close(fos); Files.move(incompleteFile, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } finally { close(is); close(fos); } } setProgress(100); } catch (Throwable e) { e.printStackTrace(); onError(e); GUIMediator.safeInvokeLater(new Runnable() { public void run() { LibraryMediator.instance().getLibrarySearch() .pushStatus(I18n.tr("Wi-Fi download error. Please try again.")); } }); } finally { GUIMediator.safeInvokeLater(new Runnable() { public void run() { LibraryMediator.instance().getLibrarySearch().revertStatus(); } }); if (lastFile != null) { GUIMediator.launchExplorer(lastFile); } } stop(); }
From source file:edu.stolaf.cs.wmrserver.TransformProcessor.java
private File relativizeFile(File file, File relativeToFile) { URI fileURI = file.toURI();/*from ww w . j a v a 2s .c o m*/ URI rtURI = relativeToFile.getAbsoluteFile().toURI(); return new File(rtURI.relativize(fileURI).getPath()); }
From source file:Json.Type.java
public Type(String type) { JSONObject obj = new JSONObject(); obj.put("type", type); File file = new File("type"); try {/* w w w.j a va2 s .com*/ //?, ? ?? ? if (!file.exists()) { file.createNewFile(); } //PrintWriter ? ? ? PrintWriter out = new PrintWriter(file.getAbsoluteFile()); try { //? ? out.print(obj); } finally { //? // ?? out.close(); } } catch (IOException e) { throw new RuntimeException(e); } }