示例#1
0
 public Writer flush() {
   try {
     if (appendable instanceof Flushable) {
       Flushable flushable = (Flushable) appendable;
       flushable.flush();
     }
   } catch (java.io.IOException e) {
     throw new IOException(e);
   }
   return this;
 }
示例#2
0
  /** @param targets objects to flush, null is permitted */
  public static void flush(final Flushable... targets) {
    if (targets != null) {
      for (Flushable f : targets) {
        if (f == null) {
          continue;
        }

        try {
          f.flush();
        } catch (IOException e) {
          log.trace(e.getMessage(), e);
        }
      }
    }
  }
示例#3
0
 @Override
 public void flush() throws IOException {
   checkNotClosed();
   if (target instanceof Flushable) {
     ((Flushable) target).flush();
   }
 }
示例#4
0
文件: Streams.java 项目: GTDaven/nutz
 /**
  * 安全刷新一个可刷新的对象,可接受 null
  *
  * @param fa 可刷新对象
  */
 public static void safeFlush(Flushable fa) {
   if (null != fa)
     try {
       fa.flush();
     } catch (IOException e) {
     }
 }
示例#5
0
 public void flushQuietly(Flushable s) {
   if (s != null) {
     try {
       s.flush();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
示例#6
0
  @Override
  protected void runTask() throws Exception {

    progress.setState(State.RUNNING);

    int mergeCount = 0;

    T a = sourceA.hasNext() ? sourceA.read() : null;
    T b = sourceB.hasNext() ? sourceB.read() : null;
    while (a != null && b != null) {
      final int c = comparator.compare(a, b);
      if (c < 0) {
        sink.write(a);
        a = sourceA.hasNext() ? sourceA.read() : null;
      } else if (c > 0) {
        sink.write(b);
        b = sourceB.hasNext() ? sourceB.read() : null;
      } else {
        sink.write(a);
        sink.write(b);
        a = sourceA.hasNext() ? sourceA.read() : null;
        b = sourceB.hasNext() ? sourceB.read() : null;
      }
      ++mergeCount;

      if (mergeCount % 1000000 == 0) {
        progress.setMessage(MessageFormat.format("Merged {0} unique items.", mergeCount));
      }
    }
    while (a != null) {
      sink.write(a);
      a = sourceA.hasNext() ? sourceA.read() : null;
      ++mergeCount;

      if (mergeCount % 1000000 == 0) {
        progress.setMessage(MessageFormat.format("Merged {0} unique items.", mergeCount));
      }
    }
    while (b != null) {
      sink.write(b);
      b = sourceB.hasNext() ? sourceB.read() : null;
      ++mergeCount;

      if (mergeCount % 1000000 == 0) {
        progress.setMessage(MessageFormat.format("Merged {0} unique items.", mergeCount));
      }
    }

    progress.startAdjusting();
    progress.setMessage(MessageFormat.format("Merged {0} unique items.", mergeCount));
    progress.setState(State.COMPLETED);
    progress.endAdjusting();

    if (sink instanceof Flushable) ((Flushable) sink).flush();
  }
示例#7
0
 public static void flush(Flushable var0, boolean var1) throws IOException {
   try {
     var0.flush();
   } catch (IOException var5) {
     Logger var3 = logger;
     Level var4 = Level.WARNING;
     var3.log(var4, "IOException thrown while flushing Flushable.", var5);
     if (!var1) {
       throw var5;
     }
   }
 }
示例#8
0
  protected boolean flush(Flushable flushable) {
    if (flushable != null) {
      try {
        flushable.flush();

        return true;
      } catch (IOException e) {
        // mute
      }
    }

    return false;
  }
示例#9
0
文件: IO.java 项目: kdchamil/ASTomEE
 public static void close(final Closeable closeable) {
   if (closeable == null) return;
   try {
     if (Flushable.class.isInstance(closeable)) {
       ((Flushable) closeable).flush();
     }
   } catch (Throwable e) {
     // Ignore
   }
   try {
     closeable.close();
   } catch (Throwable e) {
     // Ignore
   }
 }
示例#10
0
 /**
  * Method that will close an {@link java.io.Closeable} ignoring it if it is null and ignoring
  * exceptions.
  *
  * @param closeable the closeable to close.
  * @since jEdit 4.3pre8
  */
 public static void closeQuietly(Closeable closeable) {
   if (closeable != null) {
     try {
       if (closeable instanceof Flushable) {
         ((Flushable) closeable).flush();
       }
     } catch (IOException e) {
       // ignore
     }
     try {
       closeable.close();
     } catch (IOException e) {
       // ignore
     }
   }
 } // }}}
示例#11
0
 /**
  * Method that will close a {@link Writer} ignoring it if it is null and ignoring exceptions.
  *
  * @param out the Writer to close.
  */
 public static void closeQuietly(Writer out) {
   if (out != null) {
     try {
       if (out instanceof Flushable) {
         ((Flushable) out).flush();
       }
     } catch (IOException e) {
       // ignore
     }
     try {
       out.close();
     } catch (IOException e) {
       // ignore
     }
   }
 }
示例#12
0
  public static void flushAndCloseQuietly(Closeable closeable) {
    if (closeable == null) {
      return; // nothing to do
    }

    try {
      if (closeable instanceof Flushable) {
        ((Flushable) closeable).flush();
      }
    } catch (IOException e) {
      /* ignore */
    }

    try {
      closeable.close();
    } catch (IOException ignore) {
      /* ignore */
    }
  }
示例#13
0
 private static void close(Closeable[] streams, int idx) throws IOException {
   if (idx >= streams.length) {
     return; // done
   }
   Closeable stream = streams[idx];
   try {
     if (stream != null) {
       if (stream instanceof Flushable) {
         ((Flushable) stream).flush();
       }
       stream.close();
     }
   } catch (IOException ex) {
     if (!(stream instanceof InputStream || stream instanceof Reader)) {
       throw ex; // ignore io exceptions for input streams and readers
     }
   } finally {
     close(streams, idx + 1);
   }
 }
 private void flush(GaugeWriter writer) {
   if (writer instanceof CompositeMetricWriter) {
     for (MetricWriter child : (CompositeMetricWriter) writer) {
       flush(child);
     }
   }
   try {
     if (ClassUtils.isPresent("java.io.Flushable", null)) {
       if (writer instanceof Flushable) {
         ((Flushable) writer).flush();
         return;
       }
     }
     Method method = ReflectionUtils.findMethod(writer.getClass(), "flush");
     if (method != null) {
       ReflectionUtils.invokeMethod(method, writer);
     }
   } catch (Exception ex) {
     logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage());
   }
 }
示例#15
0
 public static void flush(Object o) throws IOException {
   if (o instanceof Flushable) ((Flushable) o).flush();
 }
示例#16
0
 public void flush() throws IOException {
   if (delegate instanceof Flushable) {
     ((Flushable) delegate).flush();
   }
 }
示例#17
0
 @Override
 public void flush(@Nonnull Flushable flushable) throws IOException {
   if (shouldFlush()) flushable.flush();
 }