Search in sources :

Example 6 with NullWriter

use of org.apache.commons.io.output.NullWriter in project hudson-2.x by hudson.

the class JDKInstaller method locateStage1.

// dom4j doesn't do generics, apparently... should probably switch to XOM
@SuppressWarnings("unchecked")
private HttpURLConnection locateStage1(Platform platform, CPU cpu) throws IOException {
    URL url = new URL("https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=" + id);
    String cookie;
    Element form;
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        cookie = con.getHeaderField("Set-Cookie");
        LOGGER.fine("Cookie=" + cookie);
        Tidy tidy = new Tidy();
        tidy.setErrout(new PrintWriter(new NullWriter()));
        DOMReader domReader = new DOMReader();
        Document dom = domReader.read(tidy.parseDOM(con.getInputStream(), null));
        form = null;
        for (Element e : (List<Element>) dom.selectNodes("//form")) {
            String action = e.attributeValue("action");
            LOGGER.fine("Found form:" + action);
            if (action.contains("ViewFilteredProducts")) {
                form = e;
                break;
            }
        }
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
    url = new URL(form.attributeValue("action"));
    try {
        HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        con.setRequestProperty("Cookie", cookie);
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        PrintStream os = new PrintStream(con.getOutputStream());
        // select platform
        String primary = null, secondary = null;
        Element p = (Element) form.selectSingleNode(".//select[@id='dnld_platform']");
        for (Element opt : (List<Element>) p.elements("option")) {
            String value = opt.attributeValue("value");
            String vcap = value.toUpperCase(Locale.ENGLISH);
            if (!platform.is(vcap))
                continue;
            switch(cpu.accept(vcap)) {
                case PRIMARY:
                    primary = value;
                    break;
                case SECONDARY:
                    secondary = value;
                    break;
                case UNACCEPTABLE:
                    break;
            }
        }
        if (primary == null)
            primary = secondary;
        if (primary == null)
            throw new AbortException("Couldn't find the right download for " + platform + " and " + cpu + " combination");
        os.print(p.attributeValue("name") + '=' + primary);
        LOGGER.fine("Platform choice:" + primary);
        // select language
        Element l = (Element) form.selectSingleNode(".//select[@id='dnld_language']");
        if (l != null) {
            os.print("&" + l.attributeValue("name") + "=" + l.element("option").attributeValue("value"));
        }
        // the rest
        for (Element e : (List<Element>) form.selectNodes(".//input")) {
            os.print('&');
            os.print(e.attributeValue("name"));
            os.print('=');
            String value = e.attributeValue("value");
            if (value == null)
                // assume this is a checkbox
                os.print("on");
            else
                os.print(URLEncoder.encode(value, "UTF-8"));
        }
        os.close();
        return con;
    } catch (IOException e) {
        throw new IOException2("Failed to access " + url, e);
    }
}
Also used : PrintStream(java.io.PrintStream) Element(org.dom4j.Element) IOException(java.io.IOException) Document(org.dom4j.Document) Tidy(org.w3c.tidy.Tidy) URL(java.net.URL) NullWriter(org.apache.commons.io.output.NullWriter) DOMReader(org.dom4j.io.DOMReader) HttpURLConnection(java.net.HttpURLConnection) ArrayList(java.util.ArrayList) List(java.util.List) IOException2(hudson.util.IOException2) PrintWriter(java.io.PrintWriter) AbortException(hudson.AbortException)

Example 7 with NullWriter

use of org.apache.commons.io.output.NullWriter in project rest.li by linkedin.

the class DocletDocsProvider method registerSourceFiles.

@Override
public void registerSourceFiles(Collection<String> sourceFileNames) {
    log.info("Executing Javadoc tool...");
    final String flatClasspath;
    if (_classpath == null) {
        flatClasspath = System.getProperty("java.class.path");
    } else {
        flatClasspath = StringUtils.join(_classpath, ":");
    }
    final PrintWriter sysoutWriter = new PrintWriter(System.out, true);
    final PrintWriter nullWriter = new PrintWriter(new NullWriter());
    final List<String> javadocArgs = new ArrayList<String>(Arrays.asList("-classpath", flatClasspath, "-sourcepath", StringUtils.join(_sourcePaths, ":")));
    if (_resourcePackages != null) {
        javadocArgs.add("-subpackages");
        javadocArgs.add(StringUtils.join(_resourcePackages, ":"));
    } else {
        javadocArgs.addAll(sourceFileNames);
    }
    _doclet = RestLiDoclet.generateDoclet(_apiName, sysoutWriter, nullWriter, nullWriter, javadocArgs.toArray(new String[0]));
}
Also used : ArrayList(java.util.ArrayList) NullWriter(org.apache.commons.io.output.NullWriter) PrintWriter(java.io.PrintWriter)

Example 8 with NullWriter

use of org.apache.commons.io.output.NullWriter in project sonarqube by SonarSource.

the class DdlUtils method newScriptRunner.

private static ScriptRunner newScriptRunner(Connection connection) {
    ScriptRunner scriptRunner = new ScriptRunner(connection);
    scriptRunner.setDelimiter(";");
    scriptRunner.setStopOnError(true);
    scriptRunner.setLogWriter(new PrintWriter(new NullWriter()));
    return scriptRunner;
}
Also used : ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) NullWriter(org.apache.commons.io.output.NullWriter) PrintWriter(java.io.PrintWriter)

Example 9 with NullWriter

use of org.apache.commons.io.output.NullWriter in project webservices-axiom by apache.

the class SerializerTest method testIllegalCharacterSequenceInProcessingInstruction.

@Test(expected = IllegalCharacterSequenceException.class)
public void testIllegalCharacterSequenceInProcessingInstruction() throws Exception {
    Serializer handler = new Serializer(new NullWriter());
    handler.startFragment();
    handler.startProcessingInstruction("test");
    handler.processCharacterData("aaa???>bbb", false);
    handler.endProcessingInstruction();
    handler.completed();
}
Also used : NullWriter(org.apache.commons.io.output.NullWriter) Test(org.junit.Test)

Aggregations

NullWriter (org.apache.commons.io.output.NullWriter)9 PrintWriter (java.io.PrintWriter)4 Test (org.junit.Test)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CharSource (com.google.common.io.CharSource)1 Injector (com.google.inject.Injector)1 AbortException (hudson.AbortException)1 IOException2 (hudson.util.IOException2)1 StringInputRowParser (io.druid.data.input.impl.StringInputRowParser)1 ExtensionsConfig (io.druid.guice.ExtensionsConfig)1 FirehoseModule (io.druid.guice.FirehoseModule)1 IndexingServiceFirehoseModule (io.druid.guice.IndexingServiceFirehoseModule)1 LocalDataStorageDruidModule (io.druid.guice.LocalDataStorageDruidModule)1 ParsersModule (io.druid.guice.ParsersModule)1 HadoopDruidIndexerConfig (io.druid.indexer.HadoopDruidIndexerConfig)1 IndexingHadoopModule (io.druid.indexer.IndexingHadoopModule)1 UOE (io.druid.java.util.common.UOE)1