/** @param lines without tailing line separator */ private T lines(Writer dest, Iterator<String> lines) throws IOException { String line; String separator; separator = getWorld().getSettings().lineSeparator.getSeparator(); while (lines.hasNext()) { line = lines.next(); dest.write(line); dest.write(separator); } dest.close(); return (T) this; }
public static void dump(Object obj, Node dest, int maxDepth) throws IOException { try (Writer writer = dest.newWriter()) { dump(dest.getWorld(), obj, writer, maxDepth); } }
public LineReader newLineReader() throws IOException { return newLineReader(getWorld().getSettings().lineFormat); }
/** @return lines without tailing line separator */ public List<String> readLines() throws IOException { return readLines(getWorld().getSettings().lineFormat); }
/** Generates an xml/encoding declaration */ public void serialize(Node src, net.oneandone.sushi.fs.Node dest, boolean format) throws IOException { // don't use Saver to allow transformer to decide about encoding */ try (OutputStream out = dest.newOutputStream()) { serialize(new DOMSource(src), new StreamResult(out), dest.getWorld().getSettings().encoding, format); } }
public static Archive loadJar(Node src) throws IOException { return createJar(src.getWorld()).read(src); }
public Copy(Node srcdir) { this(srcdir, srcdir.getWorld().filter().includeAll()); }
public static NodeWriter create(Node node, boolean append) throws NewOutputStreamException { try { return new NodeWriter(node, node.newOutputStream(append), node.getWorld().getSettings().encoding); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
public static NodeReader create(Node node) throws FileNotFoundException, NewInputStreamException { try { return new NodeReader(node, node.newInputStream(), node.getWorld().getSettings().encoding); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
public static Archive loadZip(Node src) throws IOException { return createZip(src.getWorld()).read(src); }
/** * Write the specified node into this file. Adds indentation/newlines when format is true. Otherwise, writes * the document "as is" (but always prefixes the document with an xml declaration and encloses attributes in * double quotes). * * @return this node */ public T writeXml(org.w3c.dom.Node node, boolean format) throws IOException { getWorld().getXml().getSerializer().serialize(node, this, format); return (T) this; }
/** * Reads all chars of the node. Do not use this method on large files because it's memory consuming: the string * is created from the byte array returned by readBytes. */ public String readString() throws IOException { return getWorld().getSettings().string(readBytes()); }
public Document readXml() throws IOException, SAXException { Builder builder; builder = getWorld().getXml().getBuilder(); synchronized (builder) { return builder.parse(this); } }
public void gunzip(Node dest) throws IOException { try (InputStream rawIn = newInputStream(); InputStream in = new GZIPInputStream(rawIn); OutputStream out = dest.newOutputStream()) { getWorld().getBuffer().copy(in, out); } }
/** uses default excludes */ public List<T> find(String... includes) throws IOException { return find(getWorld().filter().include(includes)); }
public void gzip(Node dest) throws IOException { try (InputStream in = newInputStream(); OutputStream rawOut = dest.newOutputStream(); OutputStream out = new GZIPOutputStream(rawOut)) { getWorld().getBuffer().copy(in, out); } }
public static ServerXml load(Node src, String stageName, String hostname) throws IOException, SAXException { return new ServerXml(src.getWorld().getXml(), src.readXml(), stageName, hostname); }
/** * Reads all bytes of the node. * * Default implementation that works for all nodes: reads the file in chunks and builds the result in memory. * Derived classes should override it if they can provide a more efficient implementation, e.g. by determining * the length first if getting the length is cheap. */ public byte[] readBytes() throws IOException { Buffer buffer; try (InputStream src = newInputStream()) { buffer = getWorld().getBuffer(); synchronized (buffer) { return buffer.readBytes(src); } } }
public String diffDirectory(Node rightdir, boolean brief) throws IOException { return new Diff(brief).directory(this, rightdir, getWorld().filter().includeAll()); }
public long copyFileFromImpl(InputStream src) throws FileNotFoundException, CopyFileFromException { try (OutputStream dest = newOutputStream()) { return getWorld().getBuffer().copy(src, dest); } catch (FileNotFoundException e) { throw e; } catch (IOException e) { throw new CopyFileFromException(this, e); } }