public void saveSerialized(String path) { try { IOUtils.writeObjectToFile(this, path); } catch (IOException e) { throw new RuntimeIOException(e); } }
public static SentimentModel loadSerialized(String path) { try { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } }
public static PrintWriter getPrintWriterOrDie(String filename) { try { return getPrintWriter(filename, defaultEncoding); } catch (IOException ioe) { throw new RuntimeIOException(ioe); } }
/** * Returns all the text in the given file with the given * encoding. If the file cannot be read (non-existent, etc.), then * the method throws an unchecked RuntimeIOException. If the caller * is willing to tolerate missing files, they should catch that * exception. */ public static String slurpFileNoExceptions(String filename, String encoding) { try { return slurpFile(filename, encoding); } catch (IOException e) { throw new RuntimeIOException("slurpFile IO problem", e); } }
public static void main(String[] args) throws IOException, ClassNotFoundException { Object o = IOUtils.readObjectFromFile(args[0]); IOUtils.writeObjectToFile(o, args[1]); } }
public FileHandler(String fileOrClasspath, String contentType) throws IOException { try (BufferedReader r = IOUtils.readerFromString(fileOrClasspath, "utf-8")) { this.content = IOUtils.slurpReader(r); } this.contentType = contentType + "; charset=utf-8"; // always encode in utf-8 } @Override
/** * Read the contents of an input stream, decoding it according to the given character encoding. * @param input The input stream to read from * @return The String representation of that input stream */ public static String slurpInputStream(InputStream input, String encoding) throws IOException { return slurpReader(encodedInputStreamReader(input, encoding)); }
/** * Returns all the text in the given file * * @return The text in the file. */ public static String slurpFile(String filename) throws IOException { return slurpFile(filename, defaultEncoding); }
/** * Returns the contents of a file as a list of strings. The list may be * empty, if the file is empty. If there is an IOException, it is caught * and null is returned. Encoding can also be specified */ public static List<String> linesFromFile(String filename,String encoding) { return linesFromFile(filename, encoding, false); }
@Override public void finish() throws Exception { IOUtils.writeObjectToFile(mentionPairs, StatisticalCorefTrainer.datasetFile); } }
/** * Returns an Iterable of the lines in the file. * * The file reader will be closed when the iterator is exhausted. IO errors * will throw an (unchecked) RuntimeIOException * * @param path The file whose lines are to be read. * @return An Iterable containing the lines from the file. */ public static Iterable<String> readLines(String path) { return readLines(path, null); }
/** * Iterate over all the files in the directory, recursively. * * @param dir The root directory. * @return All files within the directory. */ public static Iterable<File> iterFilesRecursive(final File dir) { return iterFilesRecursive(dir, (Pattern) null); }
/** Print the argument plus a NEWLINE in UTF-8, regardless of * the platform default. * * @param o String to print */ public static void println(String o) { println(o, null); }
/** * Writes a string to a temporary file, as UTF-8 * * @param contents The string to write * @param path The file path * @throws IOException In case of failure */ public static void writeStringToTempFile(String contents, String path) throws IOException { writeStringToTempFile(contents, path, "UTF-8"); }
public List<String> next() { List<String> result = nextResult; advance(); return result; }
/** * Returns all the text in the given file with the given * encoding. If the file cannot be read (non-existent, etc.), then * the method throws an unchecked RuntimeIOException. If the caller * is willing to tolerate missing files, they should catch that * exception. */ public static String slurpFileNoExceptions(String filename) { try { return slurpFile(filename); } catch (IOException e) { throw new RuntimeIOException(e); } }
public void saveModel(String path) { try { IOUtils.writeObjectToFile(this, path); } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * Returns all the text in the given file with the given encoding. * The string may be empty, if the file is empty. */ public static String slurpFile(String filename, String encoding) throws IOException { Reader r = readerFromString(filename, encoding); return IOUtils.slurpReader(r); }
/** * Returns the contents of a file as a list of strings. The list may be * empty, if the file is empty. If there is an IOException, it is caught * and null is returned. */ public static List<String> linesFromFile(String filename) { return linesFromFile(filename, defaultEncoding); }
@Override public void finish() throws Exception { IOUtils.writeObjectToFile(mentionTypes, StatisticalCorefTrainer.mentionTypesFile); IOUtils.writeObjectToFile(goldClusters, StatisticalCorefTrainer.goldClustersFile); if (countWords) { IOUtils.writeObjectToFile(wordCounts, StatisticalCorefTrainer.wordCountsFile); } } }