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

Class Flushables

output/java_guava/1.4.18/Flushables.java:32–80  ·  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

30
31
32@Beta
33@GwtIncompatible
34public final class Flushables {
35 private static final Logger logger = Logger.getLogger(Flushables.class.getName());
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
52
53 public static void flush(Flushable flushable, boolean swallowIOException) throws IOException {
54 try {
55 flushable.flush();
56 } catch (IOException e) {
57 if (swallowIOException) {
58 logger.log(Level.WARNING, "IOException thrown while flushing Flushable.", e);
59 } else {
60 throw e;
61 }
62 }
63 }
64
65 /**
66 * Equivalent to calling {@code flush(flushable, true)}, but with no {@code IOException} in the
67 * signature.
68 *
69 * @param flushable the {@code Flushable} object to be flushed.
70 */
71
72
73 public static void flushQuietly(Flushable flushable) {
74 try {
75 flush(flushable, true);
76 } catch (IOException e) {
77 logger.log(Level.SEVERE, "IOException should not have been thrown.", e);
78 }
79 }
80}

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.45

Tested by

no test coverage detected