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); } } }
private PrintWriter getWriter(String fileName, String suffix) { fileName = fileName.substring(0, fileName.length() - 3); String outputFile = fileName + suffix; trace("Created file: " + outputFile); try { return new PrintWriter(IOUtils.getBufferedWriter( FileUtils.newOutputStream(outputFile, false))); } catch (IOException e) { throw DbException.convertIOException(e, null); } }
/** * 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, StandardCharsets.ISO_8859_1); LineNumberReader r = new LineNumberReader(reader); Writer w; try { w = new OutputStreamWriter(FileUtils.newOutputStream(fileName, false)); } catch (Exception e) { throw new IOException(e.toString(), e); } try (PrintWriter writer = new PrintWriter(new BufferedWriter(w))) { while (true) { String line = r.readLine(); if (line == null) { break; } if (!line.startsWith("#")) { writer.print(line + "\n"); } } } }
/** * 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); }
File classFile = new File(dir, className + ".class"); try { OutputStream f = FileUtils.newOutputStream(javaFile.getAbsolutePath(), false); Writer out = IOUtils.getBufferedWriter(f); classFile.delete();
out = new PrintWriter( new OutputStreamWriter( FileUtils.newOutputStream(fileName + ".log", true))); testDatabase(fileName, out); } catch (IOException e) {
@Override public void run() { while (!stopNow) { try { SortedProperties sp = new SortedProperties(); if (file.exists()) { InputStream in = FileUtils.newInputStream(file.getName()); sp.load(in); translation.putAll(sp); } else { OutputStream out = FileUtils.newOutputStream(file.getName(), false); sp.putAll(translation); sp.store(out, "Translation"); } Thread.sleep(1000); } catch (Exception e) { traceError(e); } } }
PrintWriter javaWriter = new PrintWriter( IOUtils.getBufferedWriter( FileUtils.newOutputStream(javaClassName + ".java", false))); PrintWriter scriptWriter = new PrintWriter( IOUtils.getBufferedWriter( FileUtils.newOutputStream(script, false))); javaWriter.println("import java.io.*;"); javaWriter.println("import java.sql.*;");
OutputStream o = null; try { o = FileUtils.newOutputStream( directory + SysProperties.FILE_SEPARATOR + fileName, false); IOUtils.copy(zipIn, o);
/** * Save the lock file. * * @return the saved properties */ public Properties save() { try { try (OutputStream out = FileUtils.newOutputStream(fileName, false)) { properties.store(out, MAGIC); } lastWrite = FileUtils.lastModified(fileName); if (trace.isDebugEnabled()) { trace.debug("save " + properties); } return properties; } catch (IOException e) { throw getExceptionFatal("Could not save properties " + fileName, e); } }
OutputStream out = FileUtils.newOutputStream(fileName, false); out.write(data); out.close();
OutputStream out = FileUtils.newOutputStream( serverPropertiesDir + "/" + Constants.SERVER_PROPERTIES_NAME, false); prop.store(out, "H2 Server Properties");
/** * Open the output stream. */ void openOutput() { String file = getFileName(); if (file == null) { return; } if (isEncrypted()) { initStore(); out = new FileStoreOutputStream(store, 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; }
OutputStream fileOut = null; try { fileOut = FileUtils.newOutputStream(zipFileName, false); try (ZipOutputStream zipOut = new ZipOutputStream(fileOut)) { String base = "";
private void dumpLob(String fileName, boolean lobCompression) { OutputStream fileOut = null; FileStore fileStore = null; long size = 0; String n = fileName + (lobCompression ? ".comp" : "") + ".txt"; InputStream in = null; try { fileOut = FileUtils.newOutputStream(n, false); fileStore = FileStore.open(null, fileName, "r"); fileStore.init(); in = new FileStoreInputStream(fileStore, this, lobCompression, false); size = IOUtils.copy(in, fileOut); } catch (Throwable e) { // this is usually not a problem, because we try both compressed and // uncompressed } finally { IOUtils.closeSilently(fileOut); IOUtils.closeSilently(in); closeSilently(fileStore); } if (size == 0) { try { FileUtils.delete(n); } catch (Exception e) { traceError(n, e); } } }
try (OutputStream zip = FileUtils.newOutputStream(fileName, false)) { ZipOutputStream out = new ZipOutputStream(zip); db.flush();
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); } } }
private PrintWriter getWriter(String fileName, String suffix) { fileName = fileName.substring(0, fileName.length() - 3); String outputFile = fileName + suffix; trace("Created file: " + outputFile); try { return new PrintWriter(IOUtils.getBufferedWriter( FileUtils.newOutputStream(outputFile, false))); } catch (IOException e) { throw DbException.convertIOException(e, null); } }
/** * 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); }