@Override public void displayFile( FileSystem fs, Path path, OutputStream outStream, int startLine, int endLine) throws IOException { FSDataInputStream in = null; try { in = fs.open(path, 16 * 1024 * 1024); long endTime = System.currentTimeMillis() + STOP_TIME; BasicBSONCallback callback = new BasicBSONCallback(); BasicBSONDecoder decoder = new BasicBSONDecoder(); /* * keep reading and rendering bsonObjects until one of these conditions is met: * * a. we have rendered all bsonObjects desired. * b. we have run out of time. */ for (int lineno = 1; lineno <= endLine && System.currentTimeMillis() <= endTime; lineno++) { if (lineno < startLine) { continue; } callback.reset(); decoder.decode(in, callback); BSONObject value = (BSONObject) callback.get(); StringBuilder bldr = new StringBuilder(); bldr.append("\n\n Record "); bldr.append(lineno); bldr.append('\n'); JSON.serialize(value, bldr); outStream.write(bldr.toString().getBytes("UTF-8")); } } catch (IOException e) { outStream.write(("Error in display avro file: " + e.getLocalizedMessage()).getBytes("UTF-8")); } finally { if (in != null) { in.close(); } outStream.flush(); } }
@Override public void displayFile(FileSystem fs, Path path, OutputStream outStream, int startLine, int endLine) throws IOException { FSDataInputStream in = null; try { in = fs.open(path, 16 * 1024 * 1024); long endTime = System.currentTimeMillis() + STOP_TIME; BasicBSONCallback callback = new BasicBSONCallback(); BasicBSONDecoder decoder = new BasicBSONDecoder(); /* * keep reading and rendering bsonObjects until one of these conditions is * met: * * a. we have rendered all bsonObjects desired. b. we have run out of * time. */ for (int lineno = 1; lineno <= endLine && System.currentTimeMillis() <= endTime; lineno++) { if (lineno < startLine) { continue; } callback.reset(); decoder.decode(in, callback); BSONObject value = (BSONObject) callback.get(); StringBuilder bldr = new StringBuilder(); bldr.append("\n\n Record "); bldr.append(lineno); bldr.append('\n'); JSON.serialize(value, bldr); outStream.write(bldr.toString().getBytes("UTF-8")); } } catch (IOException e) { outStream .write(("Error in display avro file: " + e.getLocalizedMessage()) .getBytes("UTF-8")); } finally { if (in != null) { in.close(); } outStream.flush(); } }