Exemple #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;
 }
Exemple #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);
        }
      }
    }
  }
Exemple #3
0
 @Override
 public void flush() throws IOException {
   checkNotClosed();
   if (target instanceof Flushable) {
     ((Flushable) target).flush();
   }
 }
Exemple #4
0
 /**
  * 安全刷新一个可刷新的对象,可接受 null
  *
  * @param fa 可刷新对象
  */
 public static void safeFlush(Flushable fa) {
   if (null != fa)
     try {
       fa.flush();
     } catch (IOException e) {
     }
 }
Exemple #5
0
 public void flushQuietly(Flushable s) {
   if (s != null) {
     try {
       s.flush();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Exemple #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();
  }
Exemple #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;
     }
   }
 }
Exemple #8
0
  protected boolean flush(Flushable flushable) {
    if (flushable != null) {
      try {
        flushable.flush();

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

    return false;
  }
Exemple #9
0
 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
   }
 }
Exemple #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
     }
   }
 } // }}}
Exemple #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
     }
   }
 }
  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 */
    }
  }
Exemple #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());
   }
 }
Exemple #15
0
 public static void flush(Object o) throws IOException {
   if (o instanceof Flushable) ((Flushable) o).flush();
 }
Exemple #16
0
 public void flush() throws IOException {
   if (delegate instanceof Flushable) {
     ((Flushable) delegate).flush();
   }
 }
 @Override
 public void flush(@Nonnull Flushable flushable) throws IOException {
   if (shouldFlush()) flushable.flush();
 }