MCPcopy Create free account
hub / github.com/antlr/codebuff / Flushables

Class Flushables

corpus/java/training/guava/io/Flushables.java:31–76  ·  view source on GitHub ↗

Utility methods for working with Flushable objects. @author Michael Lancaster @since 1.0

Source from the content-addressed store, hash-verified

29 * @since 1.0
30 */
31@Beta
32@GwtIncompatible
33public final class Flushables {
34 private static final Logger logger = Logger.getLogger(Flushables.class.getName());
35
36 private Flushables() {}
37
38 /**
39 * Flush a {@link Flushable}, with control over whether an {@code IOException} may be thrown.
40 *
41 * <p>If {@code swallowIOException} is true, then we don't rethrow {@code IOException}, but merely
42 * log it.
43 *
44 * @param flushable the {@code Flushable} object to be flushed.
45 * @param swallowIOException if true, don't propagate IO exceptions thrown by the {@code flush}
46 * method
47 * @throws IOException if {@code swallowIOException} is false and {@link Flushable#flush} throws
48 * an {@code IOException}.
49 * @see Closeables#close
50 */
51 public static void flush(Flushable flushable, boolean swallowIOException) throws IOException {
52 try {
53 flushable.flush();
54 } catch (IOException e) {
55 if (swallowIOException) {
56 logger.log(Level.WARNING, "IOException thrown while flushing Flushable.", e);
57 } else {
58 throw e;
59 }
60 }
61 }
62
63 /**
64 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
65 * signature.
66 *
67 * @param flushable the {@code Flushable} object to be flushed.
68 */
69 public static void flushQuietly(Flushable flushable) {
70 try {
71 flush(flushable, true);
72 } catch (IOException e) {
73 logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
74 }
75 }
76}

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.45

Tested by

no test coverage detected