use of java.io.OutputStreamWriter in project che by eclipse.
the class TagListWriter method writeTo.
/**
* @see MessageBodyWriter#writeTo(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType,
* javax.ws.rs.core.MultivaluedMap, java.io.OutputStream)
*/
@Override
public void writeTo(Iterable<Tag> tags, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(entityStream);
for (Tag tag : tags) {
writer.write(tag.getName());
writer.write('\n');
}
writer.flush();
}
use of java.io.OutputStreamWriter in project jetty.project by eclipse.
the class NCSARequestLog method doStart.
/* ------------------------------------------------------------ */
/**
* Set up request logging and open log file.
*
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
*/
@Override
protected synchronized void doStart() throws Exception {
if (_filename != null) {
_fileOut = new RolloverFileOutputStream(_filename, _append, _retainDays, TimeZone.getTimeZone(getLogTimeZone()), _filenameDateFormat, null);
_closeOut = true;
LOG.info("Opened " + getDatedFilename());
} else
_fileOut = System.err;
_out = _fileOut;
synchronized (this) {
_writer = new OutputStreamWriter(_out);
}
super.doStart();
}
use of java.io.OutputStreamWriter in project whirr by apache.
the class HadoopServiceTest method test.
@Test
public void test() throws Exception {
Configuration conf = getConfiguration();
JobConf job = new JobConf(conf, HadoopServiceTest.class);
JobClient client = new JobClient(job);
waitForTaskTrackers(client);
FileSystem fs = FileSystem.get(conf);
OutputStream os = fs.create(new Path("input"));
Writer wr = new OutputStreamWriter(os);
wr.write("b a\n");
wr.close();
job.setMapperClass(TokenCountMapper.class);
job.setReducerClass(LongSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
FileInputFormat.setInputPaths(job, new Path("input"));
FileOutputFormat.setOutputPath(job, new Path("output"));
JobClient.runJob(job);
FSDataInputStream in = fs.open(new Path("output/part-00000"));
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
assertEquals("a\t1", reader.readLine());
assertEquals("b\t1", reader.readLine());
assertNull(reader.readLine());
reader.close();
}
use of java.io.OutputStreamWriter in project zeppelin by apache.
the class PegdownWebSequencelPlugin method createWebsequenceUrl.
public static String createWebsequenceUrl(String style, String content) {
style = StringUtils.defaultString(style, "default");
OutputStreamWriter writer = null;
BufferedReader reader = null;
String webSeqUrl = "";
try {
String query = new StringBuilder().append("style=").append(style).append("&message=").append(URLEncoder.encode(content, "UTF-8")).append("&apiVersion=1").toString();
URL url = new URL(WEBSEQ_URL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8);
writer.write(query);
writer.flush();
StringBuilder response = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
writer.close();
reader.close();
String json = response.toString();
int start = json.indexOf("?png=");
int end = json.indexOf("\"", start);
if (start != -1 && end != -1) {
webSeqUrl = WEBSEQ_URL + "/" + json.substring(start, end);
}
} catch (IOException e) {
throw new RuntimeException("Failed to get proper response from websequencediagrams.com", e);
} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(reader);
}
return webSeqUrl;
}
use of java.io.OutputStreamWriter in project lucida by claritylab.
the class ASSERT method createInputFile.
/**
* Creates a temporary file containing the sentences to be processed by ASSERT.
*
* @param ss sentences to be parsed
* @return input file
*/
private static File createInputFile(String[] ss) throws Exception {
try {
File input = File.createTempFile("assert", ".input", new File(ASSERT_DIR + "/scripts"));
// input.deleteOnExit();
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(input), "ISO-8859-1")));
for (String sentence : ss) {
pw.println(sentence);
if (pw.checkError())
throw new IOException();
}
pw.close();
if (pw.checkError())
throw new IOException();
return input;
} catch (IOException e) {
throw new IOException("Failed to create input file.");
}
}
Aggregations