List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
From source file:com.kingdee.eas.bos.pureflex.manager.sce.SCEContentProvider.java
public void writeTo(OutputStream outstream) throws IOException { Writer writer = new OutputStreamWriter(outstream, "UTF-8"); //$NON-NLS-1$ writer.write(content);//w w w . ja v a 2 s .co m writer.flush(); }
From source file:LVCoref.MMAX2.java
public static void exportMentions(Document d, String filename) { BufferedWriter writer = null; try {//from ww w . j a v a 2 s . co m writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")); } catch (java.io.IOException ex) { ex.printStackTrace(); } Utils.toWriter(writer, "<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>\n" + "<!DOCTYPE markables SYSTEM \"markables.dtd\">\n" + "<markables xmlns=\"www.eml.org/NameSpaces/" + "coref" + "\">\n"); for (Mention m : d.mentions) { String span = ""; if (m.start == m.end) span = "word_" + (m.start + 1); else span = "word_" + (m.start + 1) + ".." + "word_" + (m.end + 1); String coref_class = ""; if (d.corefClusters.get(m.corefClusterID).corefMentions.size() > 1) coref_class = "set_" + m.corefClusterID; else coref_class = "empty"; String category = "other"; if (m.category != null) { if (m.category.equals("ORG")) category = "organization"; else if (m.category.equals("LOCATION")) category = "location"; else if (m.category.equals("PERSON")) category = "person"; } Utils.toWriter(writer, "<markable id=\"markable_" + (m.id + 1) + "\" span=\"" + span + "\" coref_class=\"" + coref_class + "\" category=\"" + category + "\" mmax_level=\"coref\" rule=\"none\" type=\"none\"/>\n"); } Utils.toWriter(writer, "</markables>"); try { writer.flush(); writer.close(); } catch (IOException ex) { Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sp.Parser.Utils.java
public static synchronized void Send_TCP(Socket s, String JsonFormattedResponse) throws IOException { BufferedWriter outToClient = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "UTF-8")); outToClient.write(JsonFormattedResponse); outToClient.flush();//from ww w . j a v a 2 s . co m }
From source file:URLEncoder.java
public static String encode(String s, String enc) throws UnsupportedEncodingException { if (!needsEncoding(s)) { return s; }/*from ww w . ja v a2 s. co m*/ int length = s.length(); StringBuffer out = new StringBuffer(length); ByteArrayOutputStream buf = new ByteArrayOutputStream(10); // why 10? // w3c says // so. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buf, enc)); for (int i = 0; i < length; i++) { int c = (int) s.charAt(i); if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == ' ') { if (c == ' ') { c = '+'; } toHex(out, buf.toByteArray()); buf.reset(); out.append((char) c); } else { try { writer.write(c); if (c >= 0xD800 && c <= 0xDBFF && i < length - 1) { int d = (int) s.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { writer.write(d); i++; } } writer.flush(); } catch (IOException ex) { throw new IllegalArgumentException(s); } } } try { writer.close(); } catch (IOException ioe) { // Ignore exceptions on close. } toHex(out, buf.toByteArray()); return out.toString(); }
From source file:core.RESTCalls.RESTPost.java
public static String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true);/*from ww w . j a v a2s.c o m*/ conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream out = conn.getOutputStream(); Writer writer = new OutputStreamWriter(out, "UTF-8"); for (int i = 0; i < paramName.length; i++) { writer.write(paramName[i]); writer.write("="); writer.write(URLEncoder.encode(paramVal[i], "UTF-8")); writer.write("&"); } writer.close(); out.close(); if (conn.getResponseCode() != 200) throw new IOException(conn.getResponseMessage()); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) sb.append(line + "\n"); rd.close(); conn.disconnect(); return sb.toString(); }
From source file:com.dm.estore.common.utils.FileUtils.java
/** * * @param inputStream Input stream to read data from. * @param outputName Target file name to write data in. *//*from w ww . ja v a 2 s . c o m*/ public static void saveFile(InputStream inputStream, String outputName) { OutputStreamWriter out = null; try { out = new OutputStreamWriter(new FileOutputStream(outputName), DEFAULT_ENCODING); final BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream)); String inputLine = inputReader.readLine(); while (inputLine != null) { out.append(inputLine); inputLine = inputReader.readLine(); if (inputLine != null) { out.append(NEW_LINE_SEP); } } inputReader.close(); } catch (Exception e) { LOG.error("Unable to write file: " + outputName, e); } finally { if (out != null) { try { out.close(); } catch (Exception e) { LOG.trace("Unable to close file: " + outputName, e); } } } }
From source file:info.hieule.framework.laravel.utils.LaravelSecurityString.java
public static void updateSecurityString(FileObject configFile) throws IOException { List<String> lines = configFile.asLines(); String newKey = RandomStringUtils.randomAlphanumeric(32); OutputStream outputStream = configFile.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"), true); // NOI18N try {/*w w w . j a va 2 s. com*/ for (String line : lines) { if (line.contains(_SECURITY_STRING_LINE)) { line = String.format(_SECURITY_STRING_FORMAT, newKey); } pw.println(line); } } finally { outputStream.close(); pw.close(); } }
From source file:base.compilations.JavaCompilation.java
@Override protected void writeUserCodeInto(File file, String code) throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { writer.write(code);/*w ww .ja v a 2 s .com*/ writer.flush(); } }
From source file:com.handany.base.generator.FreemarkerUtil.java
public static void outputProcessResult(String outputFile, Template template, Map<String, Object> varMap) { String resultString;//from w ww . j a v a 2 s . com ByteArrayOutputStream baos = null; Writer writer = null; try { baos = new ByteArrayOutputStream(); writer = new OutputStreamWriter(baos, CHARSET); template.process(varMap, writer); resultString = new String(baos.toByteArray(), CHARSET); FileUtils.writeStringToFile(new File(outputFile), resultString, CHARSET); } catch (UnsupportedEncodingException ex) { log.error(ex.getMessage(), ex); } catch (IOException | TemplateException ex) { log.error(ex.getMessage(), ex); throw new RuntimeException(ex); } finally { if (null != baos) { try { baos.close(); } catch (IOException ex) { log.warn(ex.getMessage(), ex); } } if (null != writer) { try { writer.close(); } catch (IOException ex) { log.warn(ex.getMessage(), ex); } } } }
From source file:com.amalto.core.storage.record.DataRecordDefaultWriter.java
public void write(DataRecord record, OutputStream output) throws IOException { Writer out = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); //$NON-NLS-1$ write(record, out);/*from www .ja v a 2 s . co m*/ }