FileInputStream: Class for reading bytes from a file

Description Usage Arguments Fields and Methods Author(s) Examples

Description

Package: R.io
Class FileInputStream

Object
~~|
~~+--InputStream
~~~~~~~|
~~~~~~~+--FileInputStream

Directly known subclasses:

public static class FileInputStream
extends InputStream

Class for reading bytes from a file.

Usage

1

Arguments

file

A filename string or a File object specifying the input file.

Fields and Methods

Methods:

available Returns the number of bytes currently available in input buffer.
close Closes the input stream and releases the file.
read Reads the next byte of data from the file input stream.

Methods inherited from InputStream:
available, close, finalize, mark, markSupported, read, reset, skip

Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstanciationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, save

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
path <- Package("R.io")$path
file <- file.path(path, "DESCRIPTION")

# Using a File object would also work
# file <- File(path, "DESCRIPTION")

fin <- FileInputStream(file)

printBuffer <- function(bfr, width=10) {
  s1 <- paste(formatC(bfr, digits=3), collapse=",", sep="")
  s1 <- formatC(s1, width=5*width, flag="-");
  bfr[is.element(bfr, 0:31)] <- 46;  # "."
  s2 <- paste(intToChar(bfr), collapse="")
  cat(s1, " ", s2, "\n", sep="")
}

while((bfr <- read(fin, len=10)) != -1)
  printBuffer(bfr, width=10)

close(fin)

HenrikBengtsson/R.io documentation built on May 6, 2019, 11:54 p.m.