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;
}
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;
}
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));
}
}
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();
}
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();
}
Aggregations