/** * This function displays the first 5KB of a file if it is in ASCII format. * * @param path The path of the file to display * @param request The HttpServletRequest object * @throws FileDoesNotExistException * @throws IOException * @throws InvalidPathException * @throws TException */ private void displayFile(String path, HttpServletRequest request) throws FileDoesNotExistException, InvalidPathException, IOException { TachyonClient tachyonClient = TachyonClient.getClient(mMasterInfo.getMasterAddress()); TachyonFile tFile = tachyonClient.getFile(path); if (tFile == null) { throw new FileDoesNotExistException(path); } InStream is = tFile.getInStream(OpType.READ_NO_CACHE); int len = Math.min(5 * Constants.KB, (int) tFile.getSize()); byte[] data = new byte[len]; is.read(data, 0, len); String fileData = CommonUtils.convertByteArrayToString(data); if (fileData == null) { fileData = "The requested file is not completely encoded in ascii"; } is.close(); try { tachyonClient.close(); } catch (TException e) { LOG.error(e.getMessage()); } request.setAttribute("fileData", fileData); return; }
public static void main(String[] args) throws IOException, TableDoesNotExistException, OutOfMemoryForPinFileException, InvalidPathException, FileAlreadyExistException, TException { if (args.length != 3) { System.out.println( "java -cp target/tachyon-" + Version.VERSION + "-jar-with-dependencies.jar " + "tachyon.examples.BasicRawTableOperations <TachyonMasterAddress> <FilePath>"); System.exit(-1); } sTachyonClient = TachyonClient.getClient(args[0]); sTablePath = args[1]; sWriteType = OpType.getOpType(args[2]); createRawTable(); writeParition(); readPartition(); }