Java 8 Writer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Writer class.

This code example shows how to use the following methods:close, write
		return fileContents.toString();
	} 
 
	public void write(String filePath, String content) throws IOException {
		File file = new File(filePath);
		BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
		writer.write(content);
		writer.close();
	} 
 
	public BufferedReader getReader() {
		String storageMode = getStorageMode();
		String synchMode = getSynchMode();
		BufferedReader reader = null;
 
		try { 
			if (storageMode.equals("sdcard") || synchMode.equals("sdcard")) {
				File root = Environment.getExternalStorageDirectory();
				File morgDir = new File(root, "mobileorg");
				File morgFile = new File(morgDir, fileName);
8
CodeRank
This code example shows how to use the following methods:flush, write
 
  @Override 
  public void writeTo(JSONStreamAware jsonStreamAware, Class<?> aClass, Type type, Annotation[] annotations,
                      MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
                      OutputStream outputStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(outputStream);
    jsonStreamAware.writeJSONString(writer);
    writer.write(ENTER);
    writer.flush();
  } 
 
} 
9
CodeRank
This code example shows how to use the following methods:close, write
      return null; 
    } 
    File historyFile = new File(historyRoot, "history-" + System.currentTimeMillis() + ".csv");
    OutputStreamWriter out = null;
    try { 
      out = new OutputStreamWriter(new FileOutputStream(historyFile), Charset.forName("UTF-8"));
      out.write(history);
      return Uri.parse("file://" + historyFile.getAbsolutePath());
    } catch (IOException ioe) {
      Log.w(TAG, "Couldn't access file " + historyFile + " due to " + ioe);
      return null; 
    } finally { 
      if (out != null) {
        try { 
          out.close();
        } catch (IOException ioe) {
          // do nothing 
        } 
      } 
    } 
8
CodeRank
This code example shows how to use the following methods:close, write
public class TestJobName extends ClusterMapReduceTestCase { 
 
  public void testComplexName() throws Exception { 
    OutputStream os = getFileSystem().create(new Path(getInputDir(),
        "text.txt")); 
    Writer wr = new OutputStreamWriter(os);
    wr.write("b a\n");
    wr.close();
 
    JobConf conf = createJobConf();
    conf.setJobName("[name][some other value that gets truncated internally that this test attempts to aggravate]");
 
    conf.setInputFormat(TextInputFormat.class);
 
    conf.setOutputKeyClass(LongWritable.class);
    conf.setOutputValueClass(Text.class);
 
    conf.setMapperClass(IdentityMapper.class);
 
    FileInputFormat.setInputPaths(conf, getInputDir());
8
CodeRank
This code example shows how to use the following methods:close, write
            throws ServletException, IOException { 
 
        log.info("Received request"); 
 
        Writer writer = resp.getWriter();
        writer.write("Servlet Response\n");
        SimpleStatelessSessionLocal bean = session;
        String msg = bean.echo("Hello from Servlet");
        writer.write(msg);
        writer.close();
    } 
 
    @Override 
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException { 
        this.doGet(req, resp);
    } 
} 
8
CodeRank
This code example shows how to use the following methods:close
                String encoding = params.getProperty("encoding");
                 
                response.setCharacterEncoding(encoding != null ? encoding : "UTF-8");
                Writer writer = encoding == null ?
                    response.getWriter() :
                    new OutputStreamWriter(response.getOutputStream(), encoding);
                 
                ((WriterExporter) exporter).export(project, params, engine, writer);
                writer.close();
            } else if (exporter instanceof StreamExporter) {
                response.setCharacterEncoding("UTF-8");
                 
                OutputStream stream = response.getOutputStream();
                ((StreamExporter) exporter).export(project, params, engine, stream);
                stream.close();
//          } else if (exporter instanceof UrlExporter) { 
//              ((UrlExporter) exporter).export(project, options, engine); 
            } else { 
                // TODO: Should this use ServletException instead of respondException? 
                respondException(response, new RuntimeException("Unknown exporter type"));
8
CodeRank
This code example shows how to use the following methods:close, flush
    static public void respond(HttpServletResponse response, String status, String message)
        throws IOException { 
     
        Writer w = response.getWriter();
        try { 
            JSONWriter writer = new JSONWriter(w);
            writer.object();
            writer.key("status"); writer.value(status);
            writer.key("message"); writer.value(message);
            writer.endObject();
            w.flush();
            w.close();
        } catch (JSONException e) {
            // This can never occue 
        } 
    } 
 
    static public void respondJSON(HttpServletResponse response, Jsonizable o)
        throws IOException, JSONException { 
     
8
CodeRank
This code example shows how to use the following methods:flush, write
 
  @Override 
  public void writeTo(Map map, Class<?> aClass, Type type, Annotation[] annotations,
                      MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
                      OutputStream outputStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(outputStream);
    JSONObject.writeJSONString(map, writer);
    writer.write(ENTER);
    writer.flush();
  } 
 
} 
9
CodeRank
This code example shows how to use the following methods:close, write
    fs.delete(INPUT_DIR, true);
    fs.delete(OUTPUT_DIR, true);
 
    OutputStream os = fs.create(INPUT_FILE);
 
    Writer wr = new OutputStreamWriter(os);
    wr.write("hello1\n");
    wr.write("hello2\n");
    wr.write("hello3\n");
    wr.write("hello4\n");
    wr.close();
  } 
 
  public void testMapReduceJob() throws Exception { 
 
    JobConf conf = new JobConf(TestUserDefinedCounters.class);
    conf.setJobName("UserDefinedCounters");
     
    FileSystem fs = FileSystem.get(conf);
    cleanAndCreateInput(fs);
8
CodeRank
This code example shows how to use the following methods:close, flush, write
            throw new ServletException("Response object can't be null"); 
        } 
         
        Writer w = response.getWriter();
        if (w != null) {
            w.write(content);
            w.flush();
            w.close();
        } else { 
            throw new ServletException("response returned a null writer"); 
        } 
    } 
} 
8
CodeRank

Related Java 8 Writer Questions & Answers:

See Code Examples for Java 8 Writer Methods: