public FilterInputStream newInputStreamDeleteOnClose() throws FileNotFoundException, NewInputStreamException { return new FilterInputStream(newInputStream()) { @Override public void close() throws IOException { super.close(); // opt because it may be closed twice: deleteFileOpt(); } }; }
public ObjectInputStream newObjectInputStream() throws IOException { return new ObjectInputStream(newInputStream()); }
public Transformer readXsl() throws IOException, TransformerConfigurationException { Templates templates; try (InputStream in = newInputStream()) { templates = Serializer.templates(new SAXSource(new InputSource(in))); } return templates.newTransformer(); }
public void xslt(Transformer transformer, Node dest) throws IOException, TransformerException { try (InputStream in = newInputStream(); OutputStream out = dest.newOutputStream()) { transformer.transform(new StreamSource(in), new StreamResult(out)); } }
private static void setJaxp13Validating(DocumentBuilderFactory factory, Node schema) throws IOException, SAXException { SchemaFactory sf; Source src; sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); src = new StreamSource(schema.newInputStream()); factory.setSchema(sf.newSchema(src)); }
public Document parse(net.oneandone.sushi.fs.Node node) throws SAXException, IOException { InputSource src; try (InputStream stream = node.newInputStream()) { src = new InputSource(); src.setSystemId(node.toString()); src.setByteStream(stream); return parse(src); } }
public static ClassDef load(Node node) throws IOException { ClassDef result; try (InputStream src = node.newInputStream(); Input input = new Input(src)) { result = new ClassDef(input); } catch (RuntimeException e) { throw new RuntimeException(node + ": " + e.getMessage(), e); } return result; }
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 byte[] digestBytes(String name) throws IOException, NoSuchAlgorithmException { MessageDigest digest; Buffer buffer; try (InputStream src = newInputStream()) { digest = MessageDigest.getInstance(name); synchronized (digest) { buffer = getWorld().getBuffer(); synchronized (buffer) { buffer.digest(src, digest); } return digest.digest(); } } }
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); } }
private FileNode format() throws Exception { ProcessBuilder builder; Process process; String name; FileNode tmp; builder = new ProcessBuilder(); builder.directory(null /* use current directory */); builder.command("groff", "-man", "-Tascii"); tmp = world.getTemp().createTempFile(); builder.redirectInput(ProcessBuilder.Redirect.PIPE); builder.redirectOutput(tmp.toPath().toFile()); builder.redirectError(ProcessBuilder.Redirect.INHERIT); process = builder.start(); name = command == null ? "stool" : "stool-" + command; try (InputStream src = world.resource("templates/man/man1/" + name + ".1.gz").newInputStream()) { try (GZIPInputStream unzip = new GZIPInputStream(src)) { world.getBuffer().copy(unzip, process.getOutputStream()); } } process.getOutputStream().close(); process.waitFor(); return tmp; } }
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); } }
/** * 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); } } }
try (InputStream in = file.newInputStream()) { out.putNextEntry(new ZipEntry(Strings.removeLeft(file.getPath(), pathRoot))); file.getWorld().getBuffer().copy(in, out);
try (ZipInputStream zip = new ZipInputStream(file.newInputStream())) { while (true) { entry = zip.getNextEntry();
public long copyFileToImpl(OutputStream dest, long skip) throws FileNotFoundException, CopyFileToException { long result; try (InputStream src = newInputStream()) { if (skip(src, skip)) { return 0; } result = getWorld().getBuffer().copy(src, dest); } catch (FileNotFoundException e) { throw e; } catch (IOException e) { throw new CopyFileToException(this, e); } return result; }
/** cheap diff if you only need a yes/no answer */ public boolean diff(Node right, Buffer rightBuffer) throws IOException { Buffer leftBuffer; int leftChunk; int rightChunk; boolean result; leftBuffer = getWorld().getBuffer(); try (InputStream leftSrc = newInputStream(); InputStream rightSrc = right.newInputStream()) { result = false; do { leftChunk = leftBuffer.fill(leftSrc); rightChunk = rightBuffer.fill(rightSrc); if (leftChunk != rightChunk || leftBuffer.diff(rightBuffer, leftChunk)) { result = true; break; } } while (leftChunk > 0); } return result; }