@Override public int available() throws IOException { return fsDataInputStream.available(); }
@Override public int available() throws IOException { int avail = in.available(); if (pos + avail > end) { avail = (int) (end - pos); } return avail; }
@Override public int available() throws IOException { try { return in.available(); } catch (FileNotFoundException e) { return tryOpen().available(); } catch (NullPointerException e) { // HDFS 1.x - DFSInputStream.getBlockAt() return tryOpen().available(); } catch (AssertionError e) { // assert in HDFS 1.x - DFSInputStream.getBlockAt() return tryOpen().available(); } }
private static byte [] readFile(final FileSystem fs, final Path path) throws IOException { FSDataInputStream tmpIn = fs.open(path); try { byte [] rawData = new byte[tmpIn.available()]; tmpIn.readFully(rawData); return rawData; } finally { tmpIn.close(); } }
@Override public int available() throws IOException { return datas.available() + super.available(); }
@Override public int available() throws IOException { return datas.available() + super.available(); }
/** {@inheritDoc} */ @Override public synchronized int available() throws IOException { readStart(); try { return is.available(); } finally { readEnd(); } }
/** * Load from a Hadoop filesystem. * There's a check for data availability after the file is open, by * raising an EOFException if stream.available == 0. * This allows for a meaningful exception without the round trip overhead * of a getFileStatus call before opening the file. It may be brittle * against an FS stream which doesn't return a value here, but the * standard filesystems all do. * JSON parsing and mapping problems * are converted to IOEs. * @param fs filesystem * @param path path * @return a loaded object * @throws IOException IO or JSON parse problems */ public T load(FileSystem fs, Path path) throws IOException { try (FSDataInputStream dataInputStream = fs.open(path)) { // throw an EOF exception if there is no data available. if (dataInputStream.available() == 0) { throw new EOFException("No data in " + path); } return fromJsonStream(dataInputStream); } catch (JsonProcessingException e) { throw new IOException( String.format("Failed to read JSON file \"%s\": %s", path, e), e); } }
public static void main(String[] args) throws IOException { Configuration conf = new Configuration(); conf.addResource(new Path("/hadoop/projects/hadoop-1.0.4/conf/core-site.xml")); conf.addResource(new Path("/hadoop/projects/hadoop-1.0.4/conf/hdfs-site.xml")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the file path..."); String filePath = br.readLine(); Path path = new Path(filePath); FileSystem fs = path.getFileSystem(conf); FSDataInputStream inputStream = fs.open(path); System.out.println(inputStream.available()); fs.close(); }
private String readFully(Path file) throws IOException { FSDataInputStream in = fs.open(file); byte[] b = new byte[in.available()]; in.readFully(b); in.close(); return new String(b); }
assertTrue(in.available() > 0); byte [] buffer = new byte [1024]; int read = in.read(buffer);
@Override public int available() throws IOException { int avail = in.available(); if (pos + avail > end) { avail = (int) (end - pos); } return avail; }
@Override public int available() throws IOException { int avail = in.available(); if (pos + avail > end) { avail = (int) (end - pos); } return avail; }
@Override public int available() throws IOException { int avail = in.available(); if (pos + avail > end) { avail = (int) (end - pos); } return avail; }
@Override public int available() throws IOException { try { return in.available(); } catch (FileNotFoundException e) { return tryOpen().available(); } catch (NullPointerException e) { // HDFS 1.x - DFSInputStream.getBlockAt() return tryOpen().available(); } catch (AssertionError e) { // assert in HDFS 1.x - DFSInputStream.getBlockAt() return tryOpen().available(); } }
@Override public int available() throws IOException { try { return underlyingIs.available(); } catch(FSError e) { throw FileSystemWrapper.propagateFSError(e); } }
@Override public int available() throws IOException { try{ return is.available(); } catch(FSError e) { throw FileSystemWrapper.propagateFSError(e); } }
public FSDataInputChannel(FSDataInputStream inputStream) throws IOException { if (inputStream.getWrappedStream() instanceof ByteBufferReadable) { this.isDirectRead = true; } else { /* LocalFileSystem, S3 does not support ByteBufferReadable */ this.channel = Channels.newChannel(inputStream); } this.inputStream = inputStream; this.size = inputStream.getPos() + inputStream.available(); }