Writer write - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Writer write method.

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: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, write
	 * @param out the Writer to copy to 
	 * @throws IOException in case of I/O errors 
	 */ 
	public static void copy(String in, Writer out) throws IOException {
		Assert.notNull(in, "No input String specified");
		Assert.notNull(out, "No Writer specified");
		try { 
			out.write(in);
		} 
		finally { 
			try { 
				out.close();
			} 
			catch (IOException ex) {
			} 
		} 
	} 
 
	/** 
	 * Copy the contents of the given Reader into a String. 
8
CodeRank
This code example shows how to use the following methods:write
            unicode = true;
        } 
    } 
 
    public void startDocument(String encoding, Boolean standalone) throws IOException {
        writer.write("<?xml version='1.0' ");
 
        if (encoding != null) {
            this.encoding = encoding;
            if (encoding.toLowerCase(Locale.US).startsWith("utf")) {
                unicode = true;
            } 
        } 
 
        if (this.encoding != null) {
            writer.write("encoding='");
            writer.write(this.encoding);
            writer.write("' ");
        } 
 

8
CodeRank
This code example shows how to use the following methods:flush, write
 
        @Override 
        public void writeTo(String s, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                            MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException,
                WebApplicationException { 
            OutputStreamWriter osw = new OutputStreamWriter(entityStream);
 
            if (compareAnnotations(new Class<?>[]{MyAnnotation.class, Produces.class, GET.class}, annotations)) {
                osw.write(s + "-ok");
            } else { 
                osw.write(s + "-fail");
            } 
            osw.flush();
        } 
 
        @Override 
        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return type == Bean.class;
        } 
 
8
CodeRank
This code example shows how to use the following methods:close, write
		urlConnection.setDoOutput(true);
		urlConnection.setRequestMethod("PUT");
		urlConnection.setRequestProperty("Content-Type","application/json");
		 
		if(content != null) {
			OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
			out.write(content);
			out.close();
		} 
		 
		return urlConnection.getResponseCode();
		 
		/* 
        URL url = new URL(urlString); 
        DefaultHttpClient httpClient; 
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 
        if(sp.getBoolean(SettingsActivity.CB_ALLOWALLSSLCERTIFICATES_STRING, false) && url.getProtocol().toLowerCase().equals("https")) 
            httpClient = new SSLHttpClient(context); 
        else 
            httpClient = new DefaultHttpClient(); 
7
CodeRank

Related Writer write Questions & Answers:

write Method Overview
Writes a string.
See Code Examples for other Java 8 Writer Methods: