public static String readString(InputStream in) throws IOException { return readString(new InputStreamReader(in)); }
private void prepareForWire() throws Exception { if (file != null) { // set the data data = IOUtil.readBytes(file); } else if (is != null) { // set the data data = IOUtil.readBytes(is); } else if (reader != null) { // set the data data = IOUtil.readString(reader).getBytes(); } else if (stmts != null) { // set the data and content type (TRIG by default) format = RDFFormat.TRIG; data = serialize(stmts, format); } }
public static void writeBytes(byte[] data, OutputStream out) throws IOException { transfer(new ByteArrayInputStream(data), out); }
public static String readString(URL url) throws IOException { Reader reader = urlToReader(url); try { return readString(reader); } finally { reader.close(); } }
public static boolean isZipStream(InputStream in) throws IOException { in.mark(MAGIC_NUMBER.length); byte[] fileHeader = IOUtil.readBytes(in, MAGIC_NUMBER.length); in.reset(); return Arrays.equals(MAGIC_NUMBER, fileHeader); }
/** * Read properties from the specified InputStream. * * @param in * the stream to read from. The stream will be closed by this method. * @return Properties loaded from the specified stream. The stream will be * closed by this method. * @throws IOException * when the stream could not be read properly */ public static Properties readProperties(InputStream in) throws IOException { return readProperties(in, null); }
/** * Write the specified properties to the specified file. * * @param props * the properties to write * @param file * the file to write to * @throws IOException * when the properties could not be written to the file properly */ public static void writeProperties(Properties props, File file, boolean includeDefaults) throws IOException { writeProperties(props, new FileOutputStream(file), includeDefaults); }
public static boolean isGZipStream(InputStream in) throws IOException { in.mark(MAGIC_NUMBER.length); byte[] fileHeader = IOUtil.readBytes(in, MAGIC_NUMBER.length); in.reset(); return Arrays.equals(MAGIC_NUMBER, fileHeader); } }
/** * Read properties from the specified file. * * @param propsFile * the file to read from * @return Properties loaded from the specified file * @throws IOException * when the file could not be read properly */ public static Properties readProperties(File propsFile) throws IOException { return readProperties(propsFile, null); }
/** * Save configuration properties to a file. * * @param props * the configuration properties * @param file * the file to write to * @throws IOException * if the settings could not be saved because of an I/O problem */ public static void saveConfigurationProperties(Properties props, File file, boolean includeDefaults) throws IOException { if (file.getParentFile().mkdirs() || file.getParentFile().canWrite()) { IOUtil.writeProperties(props, file, includeDefaults); } } }
/** * Read the contents as a string from the given file. */ public static String readString(File file) throws IOException { FileInputStream in = new FileInputStream(file); try { return readString(in); } finally { in.close(); } }
/** * Reads at most <tt>maxBytes</tt> bytes from the supplied input stream and * returns them as a byte array. * * @param in * The InputStream supplying the bytes. * @param maxBytes * The maximum number of bytes to read from the input stream. * @return A byte array of size <tt>maxBytes</tt> if the input stream can * produce that amount of bytes, or a smaller byte array containing * all available bytes from the stream otherwise. */ public static byte[] readBytes(InputStream in, int maxBytes) throws IOException { byte[] result = new byte[maxBytes]; int bytesRead = readBytes(in, result); if (bytesRead < maxBytes) { // Create smaller byte array byte[] tmp = new byte[bytesRead]; System.arraycopy(result, 0, tmp, 0, bytesRead); result = tmp; } return result; }
/** * Reads all bytes from the supplied input stream and returns them as a byte * array. * * @param in * The InputStream supplying the bytes. * @return A byte array containing all bytes from the supplied input stream. */ public static byte[] readBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); transfer(in, out); return out.toByteArray(); }
/** * Read properties from the specified file. * * @param propsFile * the file to read from * @param defaults * the default properties to use * @return Properties loaded from the specified file * @throws IOException * when the file could not be read properly */ public static Properties readProperties(File propsFile, Properties defaults) throws IOException { return readProperties(new FileInputStream(propsFile), defaults); }
/** * Save configuration properties to a file. * * @param props * the configuration properties * @param file * the file to write to * @throws IOException * if the settings could not be saved because of an I/O problem */ public static void saveConfigurationProperties(Properties props, File file, boolean includeDefaults) throws IOException { if (file.getParentFile().mkdirs() || file.getParentFile().canWrite()) { IOUtil.writeProperties(props, file, includeDefaults); } } }
/** * Load configuration settings from the specified file. * * @param file * the file to load from * @return the contents of the file as a String, or null if the file did not * exist * @throws IOException * if the contents of the file could not be read due to an I/O * problem */ public static String loadConfigurationContents(File file) throws IOException { String result = null; if (file.exists()) { result = IOUtil.readString(file); } return result; }
private void prepareForWire() throws Exception { if (file != null) { // set the data data = IOUtil.readBytes(file); } else if (stmts != null) { // set the data and content type (TRIG by default) format = RDFFormat.TRIG; data = serialize(stmts, format); } }
public void writeTo(OutputStream out) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter(out, charset); IOUtil.transfer(contents, writer); writer.flush(); } finally { contents.close(); } } };
/** * Load configuration properties from the specified file. * * @param file * the file to load from * @return the contents of the file as Properties, or null if the file did * not exist * @throws IOException * if the contents of the file could not be read due to an I/O * problem */ public static Properties loadConfigurationProperties(File file, Properties defaults) throws IOException { Properties result = null; if (file.exists()) { result = IOUtil.readProperties(file, defaults); } else { result = new Properties(defaults); } return result; }
public String getQueryString() throws Exception { if (queryString == null) { InputStream stream = new URL(queryFileURL).openStream(); try { return IOUtil.readString(new InputStreamReader(stream, "UTF-8")); } finally { stream.close(); } } return queryString; }