public static String read(InputStream in) { InputStreamReader reader; try { reader = new InputStreamReader(in, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.getMessage(), e); } return read(reader); }
public MorfetteFileIterator(String filename) { try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8")); primeNext(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
public static StreamEncoder forOutputStreamWriter(OutputStream out, Object lock, String charsetName) throws UnsupportedEncodingException { String csn = charsetName; if (csn == null) csn = Charset.defaultCharset().name(); try { if (Charset.isSupported(csn)) return new StreamEncoder(out, lock, Charset.forName(csn)); } catch (IllegalCharsetNameException x) { } throw new UnsupportedEncodingException (csn); }
public void setOutput(OutputStream os, String encoding) throws IOException, IllegalArgumentException, IllegalStateException { if (os == null) throw new IllegalArgumentException(); try { mCharset = Charset.forName(encoding).newEncoder(); } catch (IllegalCharsetNameException e) { throw (UnsupportedEncodingException) (new UnsupportedEncodingException( encoding).initCause(e)); } catch (UnsupportedCharsetException e) { throw (UnsupportedEncodingException) (new UnsupportedEncodingException( encoding).initCause(e)); } mOutputStream = os; }
/** * Equivalent to {@code forName} but only throws {@code UnsupportedEncodingException}, * which is all pre-nio code claims to throw. * * @hide internal use only */ public static Charset forNameUEE(String charsetName) throws UnsupportedEncodingException { try { return Charset.forName(charsetName); } catch (Exception cause) { UnsupportedEncodingException ex = new UnsupportedEncodingException(charsetName); ex.initCause(cause); throw ex; } }
private static void resolveDummyTags(File treeFile, TwoDimensionalCounter<String, String> pretermLabel, TwoDimensionalCounter<String, String> unigramTagger) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), "UTF-8")); TreeReaderFactory trf = new FrenchTreeReaderFactory(); TreeReader tr = trf.newTreeReader(br); PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(treeFile + ".fixed")),false,"UTF-8")); int nTrees = 0; for(Tree t; (t = tr.readTree()) != null;nTrees++) { traverseAndFix(t, pretermLabel, unigramTagger); pw.println(t.toString()); } pw.close(); tr.close(); System.out.println("Processed " +nTrees+ " trees"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
String currentInfile = ""; try { outfile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName),"UTF-8"))); infile = new LineNumberReader(new BufferedReader(new InputStreamReader(new FileInputStream(path),"UTF-8"))); currentInfile = path.getPath(); outfile.println(SentenceUtils.listToString(sent)); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.printf("%s: Could not open %s for writing\n", this.getClass().getName(), outFileName); } finally { if(outfile != null) outfile.close();
private void setupOutputFiles() { PrintWriter outfile = null; String curOutFileName = ""; try { outFiles = Generics.newHashMap(); for(String keyForFile : outFilenames.keySet()) { curOutFileName = outFilenames.get(keyForFile); if(!makeFlatFile && curOutFileName.contains(flatExtension)) continue; outfile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(curOutFileName),"UTF-8"))); outFiles.put(keyForFile, outfile); } } catch (UnsupportedEncodingException e) { System.err.printf("%s: Filesystem does not support UTF-8 output\n", this.getClass().getName()); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.printf("%s: Could not open %s for writing\n", this.getClass().getName(), curOutFileName); } }
final PrintWriter guessPw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePrefix + ".kworst.guess"),"UTF-8"))); final PrintWriter goldPw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePrefix + ".kworst.gold"),"UTF-8"))); final PrintWriter guessDepPw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePrefix + ".kworst.guess.deps"),"UTF-8"))); final PrintWriter goldDepPw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePrefix + ".kworst.gold.deps"),"UTF-8"))); e.printStackTrace(); e.printStackTrace();
public static void printCounter(TwoDimensionalCounter<String,String> cnt, String fname) { try { PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(fname)),false,"UTF-8")); for(String key : cnt.firstKeySet()) { for(String val : cnt.getCounter(key).keySet()) { pw.printf("%s\t%s\t%d%n", key, val, (int) cnt.getCount(key, val)); } } pw.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
if (iOut == null) { try { iOut = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(LOG_TO_FILE), "US-ASCII")); } catch (FileNotFoundException fnfe) { logger.debug("" + "Unable to open " + LOG_TO_FILE); logger.error(fnfe.getMessage(), fnfe); throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED); } catch (UnsupportedEncodingException uee) { logger.debug("" + "This system doesn't support US-ASCII encoding!!"); logger.error(uee.getMessage(), uee); throw new CompilationDeathException(CompilationDeathException.COMPILATION_ABORTED);
try (PrintWriter writer = new PrintWriter(new OutputStreamWriter( Files.newOutputStream(mydestfile.toPath()), "UTF-8"))) { writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); Document doc = DOMUtils.newDocument(); Element root = doc.createElement("tagdiff"); packageNames.stream().collect(Collectors.joining(","))); DOM_WRITER.openElement(root, writer, 0, "\t"); writer.println(); for (CvsTagEntry entry : entries) { writeTagEntry(doc, writer, entry); log(uee.toString(), Project.MSG_ERR); } catch (IOException ioe) { throw new BuildException(ioe.toString(), ioe);
public static void verify(final ClassReader cr) throws AnalyzerException, IllegalArgumentException, IllegalAccessException { try { verify(cr, new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"))); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
/** * Print changelog to file specified in task. * * @param entrySet the entry set to write. * @throws BuildException if there is an error writing changelog. */ private void writeChangeLog(final CVSEntry[] entrySet) throws BuildException { try (final PrintWriter writer = new PrintWriter( new OutputStreamWriter(Files.newOutputStream(destFile.toPath()), "UTF-8"))) { new ChangeLogWriter().printChangeLog(writer, entrySet); if (writer.checkError()) { throw new IOException("Encountered an error writing changelog"); } } catch (final UnsupportedEncodingException uee) { getProject().log(uee.toString(), Project.MSG_ERR); } catch (final IOException ioe) { throw new BuildException(ioe.toString(), ioe); } } }
/** Constructs a writer filter that prints to standard out. */ public Writer() { // Note: UTF-8 should *always* be a supported encoding. Although, // I've heard of the old M$ JVM not supporting it! Amazing. -Ac try { fEncoding = "UTF-8"; fPrinter = new PrintWriter(new OutputStreamWriter(System.out, fEncoding)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage()); } } // <init>()
private static void setRunningLocation(CliMain m) { mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); try { mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (mRunningLocation.endsWith(".jar")) { mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1); } File f = new File(mRunningLocation); mRunningLocation = f.getAbsolutePath(); }
public static String decode(String value) { if (StringUtils.isEmpty(value)) { return ""; } try { return URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
public static String encode(String value) { if (StringUtils.isEmpty(value)) { return ""; } try { return URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
private String getJarFileNameNew() { String name = this.getClass().getName().replace(".", "/") + ".class"; URL urlJar = getClass().getClassLoader().getResource(name); String urlString = urlJar.getFile(); urlString = urlString.substring(urlString.indexOf(":") + 1, urlString.indexOf("!")); try { return URLDecoder.decode(urlString, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } }
/** * returns a BufferedWriter for the output stream. * * @param os output stream * @return a bufferedReader for the output stream. */ public static BufferedWriter getBufferedWriter(OutputStream os, String encoding) { try { return new BufferedWriter(new OutputStreamWriter(os, encoding), CHAR_BUFFER_SIZE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }