List of usage examples for java.io OutputStreamWriter OutputStreamWriter
public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
From source file:com.shvet.poi.util.HexDump.java
/** * dump an array of bytes to an OutputStream * * @param data the byte array to be dumped * @param offset its offset, whatever that might mean * @param stream the OutputStream to which the data is to be * written//from www. ja v a2 s .c om * @param index initial index into the byte array * @param length number of characters to output * @throws IOException is thrown if anything goes wrong writing * the data to stream * @throws ArrayIndexOutOfBoundsException if the index is * outside the data array's bounds * @throws IllegalArgumentException if the output stream is * null */ public static void dump(final byte[] data, final long offset, final OutputStream stream, final int index, final int length) throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException { if (stream == null) { throw new IllegalArgumentException("cannot write to nullstream"); } OutputStreamWriter osw = new OutputStreamWriter(stream, UTF8); osw.write(dump(data, offset, index, length)); osw.flush(); }
From source file:edu.lafayette.metadb.web.controlledvocab.ShowVocab.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *///from ww w .jav a 2s . co m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String vocabName = request.getParameter("vocab-name"); //MetaDbHelper.note("Vocab Name in Servlet: "+vocabName); PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); JSONArray vocab = new JSONArray(); try { Set<String> vocabList = ControlledVocabDAO.getControlledVocab(vocabName); Iterator<String> itr = vocabList.iterator(); String[] term = request.getParameterValues("term"); boolean autocomplete = term != null && !(term[0].equals("")); while (itr.hasNext()) { String entry = itr.next(); if (autocomplete) { //MetaDbHelper.note("Entry: "+entry+", query: "+term[0]); if (entry.toLowerCase().startsWith(term[0].toLowerCase())) vocab.put(entry); } else vocab.put(entry); } out.print(vocab); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.flush(); }
From source file:org.lieuofs.extraction.commune.ExtractionGeTax.java
public void extraire() throws IOException { CommuneCritere critere = new CommuneCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.JANUARY, 1); critere.setDateValiditeApres(cal.getTime()); cal.set(2012, Calendar.DECEMBER, 31); critere.setDateValiditeAvant(cal.getTime()); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); Collections.sort(communes, new Comparator<ICommuneSuisse>() { @Override// www . ja v a2s .co m public int compare(ICommuneSuisse o1, ICommuneSuisse o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); // Attention, le fichier est une iste historise des communes. // Une commune peut donc figurer 2 fois dans le fichier Set<Integer> numOFS = new HashSet<Integer>(3000); int nbreCommune = 0; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionCommuneGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (ICommuneSuisse commune : communes) { if (!numOFS.contains(commune.getNumeroOFS())) { nbreCommune++; numOFS.add(commune.getNumeroOFS()); writer.write(String.valueOf(commune.getNumeroOFS())); writer.write(";"); writer.write(commune.getNomCourt()); writer.write(";"); writer.write(commune.getCanton().getCodeIso2()); writer.newLine(); System.out.println(commune.getNumeroOFS() + " " + commune.getNomCourt()); } } writer.close(); System.out.println("Nbre commune : " + nbreCommune); }
From source file:FstDotWriter.java
public FstDotWriter(SymMap sm, File f, String sig, String encoding) { symmap = sm;//from w w w. j a v a 2s. co m sigma = sig; this.encoding = encoding; // the File should be a full path to a file, constructed // appropriately on the calling side; the XML file is written there. try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), encoding)); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void writeDocument(Document doc, OutputStream os) throws IOException { try {//from w w w . ja v a2 s .c om TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); DOMSource source = new DOMSource(doc); CharsetEncoder utf8Encoder = Charset.forName("UTF-8").newEncoder(); StreamResult result = new StreamResult(new OutputStreamWriter(os, utf8Encoder)); transformer.transform(source, result); } catch (TransformerException e) { System.err.println(e.getMessage()); } }
From source file:org.lieuofs.extraction.etatpays.ExtractionGeTaX.java
public void extraire() throws IOException { EtatCritere critere = new EtatCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.DECEMBER, 31); critere.setReconnuSuisseALaDate(cal.getTime()); Set<IEtat> etats = gestionnaire.rechercher(critere); List<IEtat> listeEtat = new ArrayList<IEtat>(etats); Collections.sort(listeEtat, new Comparator<IEtat>() { @Override/* w w w . j a v a 2 s .co m*/ public int compare(IEtat o1, IEtat o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionEtatGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (IEtat etat : listeEtat) { writer.write(String.valueOf(etat.getNumeroOFS())); writer.write(";"); writer.write(etat.getFormeCourte("fr")); writer.newLine(); } writer.close(); }
From source file:jp.sf.pal.facesresponse.io.BufferedResponseStream.java
public void recycle() { byteArrayInputStream = null;/* w ww. jav a 2 s. c o m*/ if (facesOutputStream != null) { facesOutputStream.reset(); byteArrayOutputStream = facesOutputStream; try { writer = new OutputStreamWriter(byteArrayOutputStream, getEncoding()); } catch (UnsupportedEncodingException e) { log.warn("Unsupported encoding: " + getEncoding(), e); writer = new OutputStreamWriter(byteArrayOutputStream); } } else { byteArrayOutputStream = null; writer = null; facesOutputStream = null; } }
From source file:ee.ria.xroad.common.util.PasswordStore.java
private static byte[] charToByte(char[] buffer) throws IOException { if (buffer == null) { return null; }/*from w w w . j a v a2s.co m*/ ByteArrayOutputStream os = new ByteArrayOutputStream(buffer.length * 2); OutputStreamWriter writer = new OutputStreamWriter(os, UTF_8); writer.write(buffer); writer.close(); return os.toByteArray(); }
From source file:nl.flotsam.greader.http.GsonHttpMessageConverter.java
@Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Writer writer = null;// w ww . j a v a 2s .c o m try { writer = new OutputStreamWriter(outputMessage.getBody(), "UTF-8"); Gson gson = new Gson(); gson.toJson(writer); } finally { IOUtils.closeQuietly(writer); } }
From source file:me.cybermaxke.mobiletools.utils.converter.AlphaYamlConfiguration.java
@Override public void save(File file) throws IOException { Validate.notNull(file, "File cannot be null"); Files.createParentDirs(file); String data = this.saveToString(); FileOutputStream stream = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(stream, Charset.forName("UTF-8")); try {// w w w.ja va 2s .co m writer.write(data); } finally { writer.close(); } }