private void initWrite() throws IOException { if (output == null) { try { OutputStream out = FileUtils.newOutputStream(fileName, false); out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE); output = new BufferedWriter(new OutputStreamWriter(out, characterSet)); } catch (Exception e) { close(); throw DbException.convertToIOException(e); } } }
/** * Copy a file from one directory to another, or to another file. * * @param original the original file name * @param copy the file name of the copy */ public static void copyFiles(String original, String copy) throws IOException { InputStream in = FileUtils.newInputStream(original); OutputStream out = FileUtils.newOutputStream(copy, false); copyAndClose(in, out); }
/** * Store a properties file. The header and the date is not written. * * @param fileName the target file name */ public synchronized void store(String fileName) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); store(out, null); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); InputStreamReader reader = new InputStreamReader(in, "ISO8859-1"); LineNumberReader r = new LineNumberReader(reader); Writer w; try { w = new OutputStreamWriter(FileUtils.newOutputStream(fileName, false)); } catch (Exception e) { throw DbException.convertToIOException(e); } PrintWriter writer = new PrintWriter(new BufferedWriter(w)); while (true) { String line = r.readLine(); if (line == null) { break; } if (!line.startsWith("#")) { writer.print(line + "\n"); } } writer.close(); }
File classFile = new File(dir, className + ".class"); try { OutputStream f = FileUtils.newOutputStream(javaFile.getAbsolutePath(), false); PrintWriter out = new PrintWriter(IOUtils.getBufferedWriter(f)); classFile.delete();
/** * Open the output stream. */ void openOutput() { String file = getFileName(); if (file == null) { return; } if (isEncrypted()) { initStore(); out = new FileStorageOutputStream(fileStorage, this, compressionAlgorithm); // always use a big buffer, otherwise end-of-block is written a lot out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS); } else { OutputStream o; try { o = FileUtils.newOutputStream(file, false); } catch (IOException e) { throw DbException.convertIOException(e, null); } out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE); out = CompressTool.wrapOutputStream(out, compressionAlgorithm, SCRIPT_SQL); } }
private boolean openWriter() { if (printWriter == null) { try { FileUtils.createDirectories(FileUtils.getParent(fileName)); if (FileUtils.exists(fileName) && !FileUtils.canWrite(fileName)) { // read only database: don't log error if the trace file // can't be opened return false; } fileWriter = IOUtils.getBufferedWriter(FileUtils.newOutputStream(fileName, true)); printWriter = new PrintWriter(fileWriter, true); } catch (Exception e) { logWritingError(e); return false; } } return true; }
private static void backupFiles(String path, String toFile) { try (OutputStream zip = FileUtils.newOutputStream(toFile, false); ZipOutputStream out = new ZipOutputStream(zip)) { FilePath p = FilePath.get(path); if (p.isDirectory()) { String pathShortName = path.replace('\\', '/'); pathShortName = pathShortName.substring(pathShortName.lastIndexOf('/') + 1); FilePath dir = FilePath.get(path); for (FilePath map : dir.newDirectoryStream()) { String entryNameBase = pathShortName + "/" + map.getName(); for (FilePath file : map.newDirectoryStream()) { backupFile(out, file.newInputStream(), entryNameBase + "/" + file.getName()); } } } else { backupFile(out, p.newInputStream(), p.getName()); } } catch (IOException e) { throw DbException.convertIOException(e, toFile); } }