Example #1
0
 public static void main(String[] args) throws Exception {
   String uri = args[0];
   Configuration conf = new Configuration();
   FileSystem fs = FileSystem.get(URI.create(uri), conf);
   FSDataInputStream in = null;
   try {
     in = fs.open(new Path(uri));
     IOUtils.copyBytes(in, System.out, 4096, false);
     in.seek(3); // go back to pos 3 of the file
     IOUtils.copyBytes(in, System.out, 4096, false);
   } finally {
     IOUtils.closeStream(in);
   }
 }
Example #2
0
 public static int writeCompressedByteArray(DataOutput out, byte[] bytes) throws IOException {
   if (bytes != null) {
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     GZIPOutputStream gzout = new GZIPOutputStream(bos);
     try {
       gzout.write(bytes, 0, bytes.length);
       gzout.close();
       gzout = null;
     } finally {
       IOUtils.closeStream(gzout);
     }
     byte[] buffer = bos.toByteArray();
     int len = buffer.length;
     out.writeInt(len);
     out.write(buffer, 0, len);
     /* debug only! Once we have confidence, can lose this. */
     return ((bytes.length != 0) ? (100 * buffer.length) / bytes.length : 0);
   } else {
     out.writeInt(-1);
     return -1;
   }
 }