Example #1
0
 private static void run(Callable c, boolean read, int size) {
   // Count all i/o time from here, including all retry overheads
   long start_io_ms = System.currentTimeMillis();
   while (true) {
     try {
       long start_ns = System.nanoTime(); // Blocking i/o call timing - without counting repeats
       c.call();
       TimeLine.record_IOclose(start_ns, start_io_ms, read ? 1 : 0, size, Value.HDFS);
       break;
       // Explicitly ignore the following exceptions but
       // fail on the rest IOExceptions
     } catch (EOFException e) {
       ignoreAndWait(e, false);
     } catch (SocketTimeoutException e) {
       ignoreAndWait(e, false);
     } catch (S3Exception e) {
       // Preserve S3Exception before IOException
       // Since this is tricky code - we are supporting different HDFS version
       // New version declares S3Exception as IOException
       // But old versions (0.20.xxx) declares it as RuntimeException
       // So we have to catch it before IOException !!!
       ignoreAndWait(e, false);
     } catch (IOException e) {
       ignoreAndWait(e, true);
     } catch (Exception e) {
       throw Log.errRTExcept(e);
     }
   }
 }
Example #2
0
 public static File writeFile(String content) {
   try {
     return writeFile(File.createTempFile("h2o", null), content);
   } catch( IOException e ) {
     throw Log.errRTExcept(e);
   }
 }
Example #3
0
 public static String readConsole() {
   BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
   try {
     return console.readLine();
   } catch( IOException e ) {
     throw  Log.errRTExcept(e);
   }
 }
Example #4
0
 // Loading/Writing ice to HDFS
 PersistHdfs(URI uri) {
   try {
     _iceRoot = new Path(uri + "/ice" + H2O.SELF_ADDRESS.getHostAddress() + "-" + H2O.API_PORT);
     // Make the directory as-needed
     FileSystem fs = FileSystem.get(_iceRoot.toUri(), CONF);
     fs.mkdirs(_iceRoot);
   } catch (Exception e) {
     throw Log.errRTExcept(e);
   }
 }
Example #5
0
 public static File writeFile(File file, String content) {
   FileWriter w = null;
   try {
     w = new FileWriter(file);
     w.write(content);
   } catch(IOException e) {
     Log.errRTExcept(e);
   } finally {
     close(w);
   }
   return file;
 }
Example #6
0
 public static String readFile(File file) {
   FileReader r = null;
   try {
     r = new FileReader(file);
     char[] data = new char[(int) file.length()];
     r.read(data);
     return new String(data);
   } catch(IOException e) {
     throw Log.errRTExcept(e);
   } finally {
     close(r);
   }
 }
Example #7
0
 public static void writeFileAndClose(File file, InputStream in) {
   OutputStream out = null;
   try {
     out = new FileOutputStream(file);
     byte[] buffer = new byte[1024];
     int len = in.read(buffer);
     while (len > 0) {
       out.write(buffer, 0, len);
       len = in.read(buffer);
     }
   } catch(IOException e) {
     throw Log.errRTExcept(e);
   } finally {
     close(in, out);
   }
 }
Example #8
0
 public static void readFile(File file, OutputStream out) {
   BufferedInputStream in = null;
   try {
     in = new BufferedInputStream(new FileInputStream(file));
     byte[] buffer = new byte[1024];
     while( true ) {
       int count = in.read(buffer);
       if( count == -1 )
         break;
       out.write(buffer, 0, count);
     }
   } catch(IOException e) {
     throw Log.errRTExcept(e);
   } finally {
     close(in);
   }
 }
Example #9
0
 private static void run(Callable c, boolean read, int size) {
   // Count all i/o time from here, including all retry overheads
   long start_io_ms = System.currentTimeMillis();
   while (true) {
     try {
       long start_ns = System.nanoTime(); // Blocking i/o call timing - without counting repeats
       c.call();
       TimeLine.record_IOclose(start_ns, start_io_ms, read ? 1 : 0, size, Value.HDFS);
       break;
       // Explicitly ignore the following exceptions but
       // fail on the rest IOExceptions
     } catch (EOFException e) {
       ignoreAndWait(e, false);
     } catch (SocketTimeoutException e) {
       ignoreAndWait(e, false);
     } catch (IOException e) {
       ignoreAndWait(e, true);
     } catch (Exception e) {
       throw Log.errRTExcept(e);
     }
   }
 }