java.io.Flushable Java Examples

The following examples show how to use java.io.Flushable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WrapProcess.java    From AndroidRipper with GNU Affero General Public License v3.0 6 votes vote down vote up
private void connect(final Readable source, final Appendable sink) {
	Thread thread = new Thread(new Runnable() {
		public void run() {
			CharBuffer cb = CharBuffer.wrap(new char [256]);
			try {
				while (source.read(cb) != -1) {
					cb.flip();
					sink.append(cb);
					cb.clear();
				}

				if (sink instanceof Flushable) {
					((Flushable)sink).flush();
				}
			} catch (IOException e) { /* prolly broken pipe, just die */ }
		}
	});
	thread.setDaemon(true);
	thread.start();
}
 
Example #2
Source File: LineReader.java    From sylph with Apache License 2.0 6 votes vote down vote up
@Override
public String readLine(String prompt, Character mask)
        throws IOException
{
    String line;
    interrupted = false;
    try {
        line = super.readLine(prompt, mask);
    }
    catch (UserInterruptException e) {
        interrupted = true;
        return null;
    }

    if (getHistory() instanceof Flushable) {
        ((Flushable) getHistory()).flush();
    }
    return line;
}
 
Example #3
Source File: AppendableWriter.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void flush() throws IOException {
  checkNotClosed();
  if (target instanceof Flushable) {
    ((Flushable) target).flush();
  }
}
 
Example #4
Source File: AnsiConsole.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AnsiConsole(Appendable target, Flushable flushable, ColorMap colorMap) {
    this.target = target;
    this.flushable = flushable;
    this.colorMap = colorMap;
    container = new Screen();
    textArea = new TextAreaImpl(container);
}
 
Example #5
Source File: AppendableFastAppendable.java    From ion-java with Apache License 2.0 5 votes vote down vote up
public void flush()
    throws IOException
{
    if (_out instanceof Flushable)
    {
        ((Flushable)_out).flush();
    }
}
 
Example #6
Source File: AsyncCoalescingStatisticsAppender.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public void close() {
   this.baseImplementation.stop();
   AppenderAttachableImpl var1 = this.downstreamAppenders;
   synchronized(this.downstreamAppenders) {
      Enumeration enumer = this.downstreamAppenders.getAllAppenders();

      while(enumer != null && enumer.hasMoreElements()) {
         Appender appender = (Appender)enumer.nextElement();
         if (appender instanceof Flushable) {
            try {
               ((Flushable)appender).flush();
            } catch (Exception var6) {
               ;
            }
         }
      }

      enumer = this.downstreamAppenders.getAllAppenders();

      while(true) {
         if (enumer == null || !enumer.hasMoreElements()) {
            break;
         }

         ((Appender)enumer.nextElement()).close();
      }
   }

   this.closed = true;
}
 
Example #7
Source File: CommonUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void flushOrLog(Flushable f, String message) {
    if (f != null) {
        try {
            f.flush();
        } catch (IOException e) {
            Fabric.getLogger().e(Fabric.TAG, message, e);
        }
    }
}
 
Example #8
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
 * signature.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 */
public static void flushQuietly(Flushable flushable) {
  try {
    flush(flushable, true);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
  }
}
 
Example #9
Source File: AppendableWriter.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void flush() throws IOException {
  checkNotClosed();
  if (target instanceof Flushable) {
    ((Flushable) target).flush();
  }
}
 
Example #10
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
 * signature.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 */


public static void flushQuietly(Flushable flushable) {
  try {
    flush(flushable, true);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
  }
}
 
Example #11
Source File: IoUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
 */
public static void flushQuietly(Flushable flushable) {
    if (flushable != null) {
        try {
            flushable.flush();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}
 
Example #12
Source File: IoUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
 */
public static void flushQuietly(Flushable flushable) {
    if (flushable != null) {
        try {
            flushable.flush();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}
 
Example #13
Source File: IoUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
/**
 * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
 */
public static void flushQuietly(Flushable flushable) {
    if (flushable != null) {
        try {
            flushable.flush();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}
 
Example #14
Source File: TaskLog.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void flushAppenders(Logger l) {
  final Enumeration<Appender> allAppenders = l.getAllAppenders();
  while (allAppenders.hasMoreElements()) {
    final Appender a = allAppenders.nextElement();
    if (a instanceof Flushable) {
      try {
        ((Flushable) a).flush();
      } catch (IOException ioe) {
        System.err.println(a + ": Failed to flush!"
          + StringUtils.stringifyException(ioe));
      }
    }
  }
}
 
Example #15
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Flush a {@link Flushable}, with control over whether an {@code IOException} may be thrown.
 *
 * <p>If {@code swallowIOException} is true, then we don't rethrow {@code IOException}, but merely
 * log it.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 * @param swallowIOException if true, don't propagate IO exceptions thrown by the {@code flush}
 *     method
 * @throws IOException if {@code swallowIOException} is false and {@link Flushable#flush} throws
 *     an {@code IOException}.
 * @see Closeables#close
 */


public static void flush(Flushable flushable, boolean swallowIOException) throws IOException {
  try {
    flushable.flush();
  } catch (IOException e) {
    if (swallowIOException) {
      logger.log(Level.WARNING, "IOException thrown while flushing Flushable.", e);
    } else {
      throw e;
    }
  }
}
 
Example #16
Source File: HttpRequest.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void done() throws IOException {
    if (this.closeable instanceof Flushable) {
        ((Flushable) this.closeable).flush();
    }
    if (this.ignoreCloseExceptions) {
        try {
            this.closeable.close();
            return;
        } catch (IOException e) {
            return;
        }
    }
    this.closeable.close();
}
 
Example #17
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
 * signature.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 */


public static void flushQuietly(Flushable flushable) {
  try {
    flush(flushable, true);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
  }
}
 
Example #18
Source File: HttpRequest.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void done() throws IOException {
	if (closeable instanceof Flushable)
		((Flushable) closeable).flush();
	if (ignoreCloseExceptions)
		try {
			closeable.close();
		} catch (IOException e) {
			// Ignored
		}
	else
		closeable.close();
}
 
Example #19
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Flush a {@link Flushable}, with control over whether an {@code IOException} may be thrown.
 *
 * <p>If {@code swallowIOException} is true, then we don't rethrow {@code IOException}, but merely
 * log it.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 * @param swallowIOException if true, don't propagate IO exceptions thrown by the {@code flush}
 *     method
 * @throws IOException if {@code swallowIOException} is false and {@link Flushable#flush} throws
 *     an {@code IOException}.
 * @see Closeables#close
 */


public static void flush(Flushable flushable, boolean swallowIOException) throws IOException {
  try {
    flushable.flush();
  } catch (IOException e) {
    if (swallowIOException) {
      logger.log(Level.WARNING, "IOException thrown while flushing Flushable.", e);
    } else {
      throw e;
    }
  }
}
 
Example #20
Source File: StreamUtil.java    From manifold with Apache License 2.0 5 votes vote down vote up
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 );
  }
}
 
Example #21
Source File: AppendableWriter.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void flush() throws IOException {
  checkNotClosed();
  if (target instanceof Flushable) {
    ((Flushable) target).flush();
  }
}
 
Example #22
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
 * signature.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 */


public static void flushQuietly(Flushable flushable) {
  try {
    flush(flushable, true);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
  }
}
 
Example #23
Source File: IOUtils.java    From AndServer with Apache License 2.0 5 votes vote down vote up
public static void flushQuietly(Flushable flushable) {
    if (flushable != null) {
        try {
            flushable.flush();
        } catch (Exception ignored) {
        }
    }
}
 
Example #24
Source File: Concatenator.java    From caja with Apache License 2.0 5 votes vote down vote up
public void noMoreTokens() {
  if (out instanceof Flushable) {
    try {
      ((Flushable) out).flush();
    } catch (IOException ex) {
      if (!closed) {
        closed = true;
        ioExceptionHandler.handle(ex);
      }
    }
  }
}
 
Example #25
Source File: TaskLog.java    From big-c with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void flushAppenders(Logger l) {
  final Enumeration<Appender> allAppenders = l.getAllAppenders();
  while (allAppenders.hasMoreElements()) {
    final Appender a = allAppenders.nextElement();
    if (a instanceof Flushable) {
      try {
        ((Flushable) a).flush();
      } catch (IOException ioe) {
        System.err.println(a + ": Failed to flush!"
          + StringUtils.stringifyException(ioe));
      }
    }
  }
}
 
Example #26
Source File: AppendableWriter.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void flush() throws IOException {
  checkNotClosed();
  if (target instanceof Flushable) {
    ((Flushable) target).flush();
  }
}
 
Example #27
Source File: IOUtils.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public static void flushQuietly(Flushable flushable) {
    if (flushable == null) return;
    try {
        flushable.flush();
    } catch (Exception e) {
        OkLogger.printStackTrace(e);
    }
}
 
Example #28
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
 * signature.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 */


public static void flushQuietly(Flushable flushable) {
  try {
    flush(flushable, true);
  } catch (IOException e) {
    logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
  }
}
 
Example #29
Source File: IOUtils.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
public static void flush(Flushable flushable) {
    try {
        flushable.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: Flushables.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Flush a {@link Flushable}, with control over whether an {@code IOException} may be thrown.
 *
 * <p>If {@code swallowIOException} is true, then we don't rethrow {@code IOException}, but merely
 * log it.
 *
 * @param flushable the {@code Flushable} object to be flushed.
 * @param swallowIOException if true, don't propagate IO exceptions thrown by the {@code flush}
 *     method
 * @throws IOException if {@code swallowIOException} is false and {@link Flushable#flush} throws
 *     an {@code IOException}.
 * @see Closeables#close
 */


public static void flush(Flushable flushable, boolean swallowIOException) throws IOException {
  try {
    flushable.flush();
  } catch (IOException e) {
    if (swallowIOException) {
      logger.log(Level.WARNING, "IOException thrown while flushing Flushable.", e);
    } else {
      throw e;
    }
  }
}