OutputStreamWriter close - top ranked examples from Open Source projects

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

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
		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
This code example shows how to use the following methods:close, write
        } 
    } 
 
    private static void generateSource(String thisClass, String otherClass) throws Exception {
        String fileName = "UnicodeTest-src" + fileSeparator + thisClass + ".java";
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");
        out.write("public class " + thisClass + " {\n");
        out.write("    public static void main(String[] args) {\n");
        out.write("        if (!" + otherClass + "." + otherClass.toLowerCase() + "().equals(\"" + otherClass + "\")) {\n");
        out.write("            throw new RuntimeException();\n");
        out.write("        }\n");
        out.write("    }\n");
        out.write("    public static String " + thisClass.toLowerCase() + "() {\n");
        out.write("        return \"" + thisClass + "\";\n");
        out.write("    }\n");
        out.write("}\n");
        out.close();
    } 
 
    private static void generateManifest(String mainClass) throws Exception {

7
CodeRank
This code example shows how to use the following methods:close
  /* 
   * Test refreshing an existing HostsFileReader with an includes file that no longer exists 
   */ 
  @Test 
  public void testRefreshHostFileReaderWithNonexistentFile() throws Exception { 
    FileWriter efw = new FileWriter(excludesFile);
    FileWriter ifw = new FileWriter(includesFile);
 
    efw.close();
 
    ifw.close();
 
    HostsFileReader hfp = new HostsFileReader(includesFile, excludesFile);
    assertTrue(INCLUDES_FILE.delete());
    try { 
      hfp.refresh();
      Assert.fail("Should throw FileNotFoundException");
    } catch (FileNotFoundException ex) {
      // Exception as expected 
    } 
7
CodeRank
This code example shows how to use the following methods:close, append
	@Override 
	protected void writeInternal(Object o, HttpOutputMessage outputMessage)
			throws IOException, HttpMessageNotWritableException {
 
		Charset charset = getCharset(outputMessage.getHeaders());
		OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);
		try { 
			if (this.jsonPrefix != null) {
				writer.append(this.jsonPrefix);
			} 
			this.gson.toJson(o, writer);
			writer.close();
		} 
		catch (JsonIOException ex) {
			throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
		} 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:close, flush
  @Override public TypedOutput toBody(Object source) { 
    OutputStreamWriter osw = null;
 
    try { 
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      osw = new OutputStreamWriter(bos, CHARSET);
      serializer.write(source, osw);
      osw.flush();
      return new TypedByteArray(MIME_TYPE, bos.toByteArray());
    } catch (Exception e) {
      throw new AssertionError(e);
    } finally { 
      try { 
        if (osw != null) {
          osw.close();
        } 
      } catch (IOException e) {
        throw new AssertionError(e);
      } 
    } 
7
CodeRank
This code example shows how to use the following methods:close, flush, write
		try { 
			String urlstr = "http://dwz.cn/create.php";
			URL requrl = new URL(urlstr);
			URLConnection conn = requrl.openConnection();
			conn.setDoOutput(true);
			OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
			String param = String.format(Locale.CHINA, "url=%s&alias=%s", url, alias);
			out.write(param);
			out.flush();
			out.close();
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line = reader.readLine();
			//{"longurl":"http:\/\/www.hao123.com\/","status":0,"tinyurl":"http:\/\/dwz.cn\/1RIKG"} 
			ObjectMapper mapper = new ObjectMapper();
			Dwz dwz = mapper.readValue(line, Dwz.class);
			if (dwz.getStatus() == 0) {
				responseData(m, dwz.getTinyurl());
			} else { 
				responseMsg(m, false, dwz.getErr_msg());
			} 
7
CodeRank
This code example shows how to use the following methods:close, write
        String fullFileName = NSPathUtilities.stringByAppendingPathExtension(GSVModel.MODEL_NAME, GSVModel.MODEL_EXTENSION);
        String xmlPath = NSPathUtilities.stringByAppendingPathComponent(_eomodelPath, fullFileName);
        try { 
            File configurationFile = new File(xmlPath);
 
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(configurationFile), "UTF-8");
            osw.write(codedString);
            osw.close();
	    NSLog.out.appendln("did save model to file"); 
            return true; 
        } catch(IOException e) {
            NSLog.out.appendln(e);
            return false; 
        } 
    } 
     
    /** 
     *	Returns the EOModelGroup that is being used to query information from the EOModel. 
     * 
     *	@return		EOModelGroup for the EOModel. 
7
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 
        } 
      } 
    } 
7
CodeRank
This code example shows how to use the following methods:close, write
        public Builder setPersonalisation(Date date, String emailAddress, String distinguisher)
        { 
            try 
            { 
                final ByteArrayOutputStream bout = new ByteArrayOutputStream();
                final OutputStreamWriter out = new OutputStreamWriter(bout, "UTF-8");
                final DateFormat format = new SimpleDateFormat("YYYYMMDD");
                out.write(format.format(date));
                out.write(" ");
                out.write(emailAddress);
                out.write(" ");
                out.write(distinguisher);
                out.close();
                return set(PARAM_TYPE_PERSONALISATION, bout.toByteArray());
            } 
            catch (IOException e)
            { 
                throw new IllegalStateException("Byte I/O failed: " + e);
            } 
        } 
7
CodeRank

Related OutputStreamWriter close Questions & Answers:

close Method Overview
Closes the stream, flushing it first.
See Code Examples for other Java 8 OutputStreamWriter Methods: