List of utility methods to do InputStream Read
ArrayList | ReadArrayOfStringPairs( FileInputStream stream) Read Array Of String Pairs int size = ReadInt(stream); ArrayList<Pair<String, String>> result = new ArrayList<Pair<String, String>>( size); for (int i = 0; i < size; ++i) { String first = ReadString(stream); String second = ReadString(stream); Pair<String, String> pair = new Pair<String, String>(first, second); ... |
int | ReadInt(FileInputStream stream) Read Int byte[] bytes = new byte[4]; if (stream.read(bytes) != 4) { return BytesToInt(bytes); |
String | ReadString(FileInputStream stream) Read String int length = ByteUtils.ReadInt(stream); byte[] buffer = new byte[length]; if (stream.read(buffer) != length) { return new String(buffer); |
String | readContents(InputStream input, String encoding) Reads in file contents. ByteArrayOutputStream out = new ByteArrayOutputStream(); FileUtil.copyContents(input, out); ByteBuffer bbuf = ByteBuffer.wrap(out.toByteArray()); Charset cset = Charset.forName(encoding); CharsetDecoder csetdecoder = cset.newDecoder(); csetdecoder.onMalformedInput(CodingErrorAction.REPORT); csetdecoder.onUnmappableCharacter(CodingErrorAction.REPORT); try { ... |
String | readFile(InputStream input) read File BufferedInputStream reader = null; String rt = null; try { byte[] buffer = new byte[input.available()]; reader = new BufferedInputStream(input); reader.read(buffer); reader.close(); input.close(); ... |
byte[] | readFully(InputStream in) read Fully if (in instanceof ByteArrayInputStream) { int size = in.available(); byte[] bytes = new byte[size]; int offset = 0; int numRead = 0; while (offset < size) { numRead = in.read(bytes, offset, size - offset); if (numRead >= 0) { ... |
String | readInputStreamToString(InputStream input, String enCoding) read Input Stream To String BufferedReader reader; StringBuilder sb = new StringBuilder(); String line = null; try { reader = new BufferedReader(new InputStreamReader(input, enCoding)); while ((line = reader.readLine()) != null) { sb.append(line + "\r\n"); ... |
void | writeToStream(InputStream in, OutputStream out, boolean closeOnExit) write To Stream byte[] bytes = new byte[2048]; for (int c = in.read(bytes); c != -1; c = in.read(bytes)) { out.write(bytes, 0, c); if (closeOnExit) { in.close(); out.close(); |
String | readStream(InputStream in) read Stream StringBuilder sb = new StringBuilder(); BufferedReader r = new BufferedReader(new InputStreamReader(in), 1024); for (String line = r.readLine(); line != null; line = r.readLine()) { sb.append(line); in.close(); return sb.toString(); ... |
String | readStream(InputStream in) read Stream StringBuilder sb = new StringBuilder(); BufferedReader r = new BufferedReader(new InputStreamReader(in), 1024); for (String line = r.readLine(); line != null; line = r.readLine()) { sb.append(line); in.close(); return sb.toString(); ... |