Android Utililty Methods InputStream Read

List of utility methods to do InputStream Read

Description

The list of methods to do InputStream Read are organized into topic(s).

Method

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);
...
intReadInt(FileInputStream stream)
Read Int
byte[] bytes = new byte[4];
if (stream.read(bytes) != 4) {
return BytesToInt(bytes);
StringReadString(FileInputStream stream)
Read String
int length = ByteUtils.ReadInt(stream);
byte[] buffer = new byte[length];
if (stream.read(buffer) != length) {
return new String(buffer);
StringreadContents(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 {
...
StringreadFile(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) {
...
StringreadInputStreamToString(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");
...
voidwriteToStream(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();
StringreadStream(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();
...
StringreadStream(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();
...