Search in sources :

Example 11 with OutputStreamWriter

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();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) Tag(org.eclipse.che.api.git.shared.Tag) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 12 with OutputStreamWriter

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();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) RolloverFileOutputStream(org.eclipse.jetty.util.RolloverFileOutputStream)

Example 13 with OutputStreamWriter

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();
}
Also used : Path(org.apache.hadoop.fs.Path) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Configuration(org.apache.hadoop.conf.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) InputStreamReader(java.io.InputStreamReader) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStream(java.io.OutputStream) BufferedReader(java.io.BufferedReader) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) OutputStreamWriter(java.io.OutputStreamWriter) JobConf(org.apache.hadoop.mapred.JobConf) JobClient(org.apache.hadoop.mapred.JobClient) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 14 with OutputStreamWriter

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 15 with OutputStreamWriter

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.");
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)3616 IOException (java.io.IOException)1453 FileOutputStream (java.io.FileOutputStream)1408 BufferedWriter (java.io.BufferedWriter)1320 Writer (java.io.Writer)939 File (java.io.File)912 PrintWriter (java.io.PrintWriter)589 InputStreamReader (java.io.InputStreamReader)510 OutputStream (java.io.OutputStream)507 BufferedReader (java.io.BufferedReader)426 ByteArrayOutputStream (java.io.ByteArrayOutputStream)373 InputStream (java.io.InputStream)255 URL (java.net.URL)242 HttpURLConnection (java.net.HttpURLConnection)208 FileNotFoundException (java.io.FileNotFoundException)207 Test (org.junit.Test)201 ArrayList (java.util.ArrayList)198 Path (org.apache.hadoop.fs.Path)194 UnsupportedEncodingException (java.io.UnsupportedEncodingException)169 FileInputStream (java.io.FileInputStream)167