Java HTML Jsoup Document saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName, final Path tmpDir)

Here you can find the source of saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName, final Path tmpDir)

Description

save Document To Directory

License

Apache License

Declaration

private static Path saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName,
            final Path tmpDir) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import java.nio.file.Files;
import java.nio.file.Path;

import java.nio.file.StandardOpenOption;

public class Main {
    private static final Charset ENCODING_UTF8 = StandardCharsets.UTF_8;

    private static Path saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName,
            final Path tmpDir) throws IOException {
        final Path outTmpPath = tmpDir.resolve(fileName);
        writeAll(outTmpPath, doc.outerHtml(), ENCODING_UTF8);
        return outTmpPath;
    }/*from w  w  w  . j  a  va  2 s .co m*/

    private static void writeAll(Path path, String data, Charset cs) throws IOException {
        try (OutputStream os = Files.newOutputStream(path, StandardOpenOption.CREATE,
                StandardOpenOption.TRUNCATE_EXISTING)) {
            os.write(data.getBytes(ENCODING_UTF8));
        }
    }
}

Related

  1. makeAbsolute(Document doc)
  2. normalizeWhitespaces(Document doc)
  3. postDocument(String url, Collection data)
  4. removeTag(Document doc, String selector)
  5. retrieveHiddenInputs(Document doc)
  6. stripTags(Document document)
  7. verifyAdultNotice(Document doc)