Search in sources :

Example 86 with OutputStreamWriter

use of java.io.OutputStreamWriter in project gitblit by gitblit.

the class SshUnitTest method testSshCommand.

protected String testSshCommand(String cmd, String stdin) throws IOException, InterruptedException {
    SshClient client = getClient();
    ClientSession session = client.connect(username, "localhost", GitBlitSuite.sshPort).await().getSession();
    session.addPublicKeyIdentity(rwKeyPair);
    assertTrue(session.auth().await().isSuccess());
    ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_EXEC, cmd);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (stdin != null) {
        Writer w = new OutputStreamWriter(baos);
        w.write(stdin);
        w.close();
    }
    channel.setIn(new ByteArrayInputStream(baos.toByteArray()));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream err = new ByteArrayOutputStream();
    channel.setOut(out);
    channel.setErr(err);
    channel.open();
    channel.waitFor(ClientChannel.CLOSED, 0);
    String result = out.toString().trim();
    channel.close(false);
    client.stop();
    return result;
}
Also used : SshClient(org.apache.sshd.client.SshClient) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.sshd.client.session.ClientSession) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) ClientChannel(org.apache.sshd.client.channel.ClientChannel)

Example 87 with OutputStreamWriter

use of java.io.OutputStreamWriter in project gitblit by gitblit.

the class TicketReferenceTest method makeCommit.

private static RevCommit makeCommit(String message) throws Exception {
    File file = new File(workingCopy, "testFile.txt");
    OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
    BufferedWriter w = new BufferedWriter(os);
    w.write("// " + new Date().toString() + "\n");
    w.close();
    git.add().addFilepattern(file.getName()).call();
    RevCommit rev = git.commit().setMessage(message).call();
    return rev;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 88 with OutputStreamWriter

use of java.io.OutputStreamWriter in project bazel by bazelbuild.

the class JavacTurbineTest method reducedClasspath.

@Test
public void reducedClasspath() throws Exception {
    Path libD = temp.newFile("libd.jar").toPath();
    compileLib(libD, Collections.<Path>emptyList(), Arrays.asList(new StringJavaFileObject("D.java", "public class D {}")));
    Path libC = temp.newFile("libc.jar").toPath();
    compileLib(libC, Collections.singleton(libD), Arrays.asList(new StringJavaFileObject("C.java", "class C { static D d; }")));
    Path libB = temp.newFile("libb.jar").toPath();
    compileLib(libB, Arrays.asList(libC, libD), Arrays.asList(new StringJavaFileObject("B.java", "class B { static C c; }")));
    Path libA = temp.newFile("liba.jar").toPath();
    compileLib(libA, Arrays.asList(libB, libC, libD), Arrays.asList(new StringJavaFileObject("A.java", "class A { static B b; }")));
    Path depsA = writedeps("liba.jdeps", Deps.Dependencies.newBuilder().setSuccess(true).setRuleLabel("//lib:a").addDependency(Deps.Dependency.newBuilder().setPath(libB.toString()).setKind(Deps.Dependency.Kind.EXPLICIT)).build());
    optionsBuilder.addClassPathEntries(ImmutableList.of(libA.toString(), libB.toString(), libC.toString(), libD.toString()));
    optionsBuilder.addAllDepsArtifacts(ImmutableList.of(depsA.toString()));
    optionsBuilder.addDirectJarToTarget(libA.toString(), "//lib:a");
    optionsBuilder.addIndirectJarToTarget(libB.toString(), "//lib:b");
    optionsBuilder.addIndirectJarToTarget(libC.toString(), "//lib:c");
    optionsBuilder.addIndirectJarToTarget(libD.toString(), "//lib:d");
    optionsBuilder.setTargetLabel("//my:target");
    addSourceLines("Hello.java", "class Hello {", "  public static A a = new A();", "  public static void main(String[] args) {", "    A a = null;", "    B b = null;", "    C c = null;", "    D d = null;", "  }", "}");
    optionsBuilder.addSources(ImmutableList.copyOf(Iterables.transform(sources, TO_STRING)));
    try (JavacTurbine turbine = new JavacTurbine(new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8))), optionsBuilder.build())) {
        assertThat(turbine.compile()).isEqualTo(Result.OK_WITH_REDUCED_CLASSPATH);
        Context context = turbine.context;
        JavacFileManager fm = (JavacFileManager) context.get(JavaFileManager.class);
        assertThat(fm.getLocationAsPaths(StandardLocation.CLASS_PATH)).containsExactly(libA, libB);
        Deps.Dependencies depsProto = getDeps();
        assertThat(depsProto.getSuccess()).isTrue();
        assertThat(depsProto.getRuleLabel()).isEqualTo("//my:target");
        assertThat(getEntries(depsProto)).containsExactlyEntriesIn(ImmutableMap.of(libA.toString(), Deps.Dependency.Kind.EXPLICIT, libB.toString(), Deps.Dependency.Kind.INCOMPLETE));
    }
}
Also used : Path(java.nio.file.Path) Context(com.sun.tools.javac.util.Context) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Deps(com.google.devtools.build.lib.view.proto.Deps) JavaFileManager(javax.tools.JavaFileManager) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 89 with OutputStreamWriter

use of java.io.OutputStreamWriter in project coursera-android by aporter.

the class InternalFileWriteReadActivity method writeFile.

private void writeFile() throws FileNotFoundException {
    FileOutputStream fos = openFileOutput(fileName, MODE_PRIVATE);
    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos)));
    pw.println("Line 1: This is a test of the File Writing API");
    pw.println("Line 2: This is a test of the File Writing API");
    pw.println("Line 3: This is a test of the File Writing API");
    pw.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 90 with OutputStreamWriter

use of java.io.OutputStreamWriter in project CoreNLP by stanfordnlp.

the class TaggerDemo2 method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        log.info("usage: java TaggerDemo2 modelFile fileToTag");
        return;
    }
    MaxentTagger tagger = new MaxentTagger(args[0]);
    TokenizerFactory<CoreLabel> ptbTokenizerFactory = PTBTokenizer.factory(new CoreLabelTokenFactory(), "untokenizable=noneKeep");
    BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "utf-8"));
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, "utf-8"));
    DocumentPreprocessor documentPreprocessor = new DocumentPreprocessor(r);
    documentPreprocessor.setTokenizerFactory(ptbTokenizerFactory);
    for (List<HasWord> sentence : documentPreprocessor) {
        List<TaggedWord> tSentence = tagger.tagSentence(sentence);
        pw.println(SentenceUtils.listToString(tSentence, false));
    }
    // print the adjectives in one more sentence. This shows how to get at words and tags in a tagged sentence.
    List<HasWord> sent = SentenceUtils.toWordList("The", "slimy", "slug", "crawled", "over", "the", "long", ",", "green", "grass", ".");
    List<TaggedWord> taggedSent = tagger.tagSentence(sent);
    for (TaggedWord tw : taggedSent) {
        if (tw.tag().startsWith("JJ")) {
            pw.println(tw.word());
        }
    }
    pw.close();
}
Also used : HasWord(edu.stanford.nlp.ling.HasWord) CoreLabelTokenFactory(edu.stanford.nlp.process.CoreLabelTokenFactory) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) CoreLabel(edu.stanford.nlp.ling.CoreLabel) TaggedWord(edu.stanford.nlp.ling.TaggedWord) MaxentTagger(edu.stanford.nlp.tagger.maxent.MaxentTagger) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) DocumentPreprocessor(edu.stanford.nlp.process.DocumentPreprocessor) PrintWriter(java.io.PrintWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)1784 IOException (java.io.IOException)690 FileOutputStream (java.io.FileOutputStream)653 BufferedWriter (java.io.BufferedWriter)647 Writer (java.io.Writer)479 File (java.io.File)407 PrintWriter (java.io.PrintWriter)296 InputStreamReader (java.io.InputStreamReader)244 OutputStream (java.io.OutputStream)221 ByteArrayOutputStream (java.io.ByteArrayOutputStream)216 BufferedReader (java.io.BufferedReader)210 Test (org.junit.Test)129 InputStream (java.io.InputStream)112 FileNotFoundException (java.io.FileNotFoundException)104 ArrayList (java.util.ArrayList)96 Path (org.apache.hadoop.fs.Path)93 UnsupportedEncodingException (java.io.UnsupportedEncodingException)92 URL (java.net.URL)90 HttpURLConnection (java.net.HttpURLConnection)78 FileInputStream (java.io.FileInputStream)71