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 Project: sylph   Author: harbby   File: LineReader.java    License: 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 #2
Source Project: AndroidRipper   Author: reverse-unina   File: WrapProcess.java    License: 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 #3
Source Project: journalkeeper   Author: chubaostream   File: StateWrapper.java    License: Apache License 2.0 5 votes vote down vote up
public StateWrapper(WrappedState<E, ER, Q, QR> wrappedState, SerializeExtensionPoint serializeExtensionPoint) {
    this.serializeExtensionPoint = serializeExtensionPoint;
    this.wrappedState = wrappedState;
    if (wrappedState instanceof Flushable) {
        flushable = (Flushable) wrappedState;
    } else {
        flushable = null;
    }
}
 
Example #4
Source Project: Bopomofo4j   Author: rnkrsoft   File: HttpRequest.java    License: Apache License 2.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 #5
Source Project: alltv   Author: PYTHONKOR   File: HttpRequest.java    License: MIT License 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 #6
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 Project: pushfish-android   Author: PushFish   File: AnsiConsole.java    License: 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 #8
Source Project: pushfish-android   Author: PushFish   File: AnsiConsole.java    License: 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 #9
Source Project: cucumber-performance   Author: mpinardi   File: NiceAppendable.java    License: MIT License 5 votes vote down vote up
private void tryFlush()  {
    if (!(out instanceof Flushable))
        return;
    try {
        ((Flushable) out).flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #10
Source Project: DoraemonKit   Author: didi   File: IOUtils.java    License: 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 #11
Source Project: DoraemonKit   Author: didi   File: IOUtils.java    License: 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 #12
Source Project: Kalle   Author: yanzhenjie   File: IOUtils.java    License: 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 #13
Source Project: firebase-android-sdk   Author: firebase   File: CommonUtils.java    License: 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) {
      Logger.getLogger().e(message, e);
    }
  }
}
 
Example #14
Source Project: text-ui   Author: alibaba   File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Flush the flushable and catch any exception thrown.
 *
 * @param flushable the flushable to flush
 * @return any Exception thrown during the <code>flush</code> operation
 */
public static Exception flush(Flushable flushable) {
  if (flushable != null) {
    try {
      flushable.flush();
    }
    catch (Exception e) {
      return e;
    }
  }
  return null;
}
 
Example #15
Source Project: android-discourse   Author: goodev   File: HttpRequest.java    License: Apache License 2.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 #16
Source Project: financisto   Author: dsolonenko   File: Csv.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source Project: letv   Author: JackChan1999   File: HttpRequest.java    License: 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 #18
Source Project: letv   Author: JackChan1999   File: CommonUtils.java    License: 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 #19
Source Project: FireFiles   Author: gigabytedevelopers   File: IoUtils.java    License: 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 #20
Source Project: FireFiles   Author: gigabytedevelopers   File: IoUtils.java    License: 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 #21
Source Project: FireFiles   Author: gigabytedevelopers   File: IoUtils.java    License: 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 #22
Source Project: hadoop   Author: naver   File: TaskLog.java    License: 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 #23
Source Project: ProtocolSupportPocketStuff   Author: ProtocolSupport   File: HttpRequest.java    License: 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 #24
Source Project: manifold   Author: manifold-systems   File: StreamUtil.java    License: 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 #25
Source Project: AndServer   Author: yanzhenjie   File: IOUtils.java    License: 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 #26
Source Project: big-c   Author: yncxcw   File: TaskLog.java    License: 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 #27
Source Project: okhttp-OkGo   Author: jeasonlzy   File: IOUtils.java    License: 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 Project: AndPermission   Author: yanzhenjie   File: IOUtils.java    License: 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 #29
Source Project: codebuff   Author: antlr   File: Flushables.java    License: 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 #30
Source Project: codebuff   Author: antlr   File: Flushables.java    License: 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);
  }
}