Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2007 The Guava Authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.common.io;
Utility methods for working with java.io.Flushable objects.

Author(s):
Michael Lancaster
Since:
1.0
public final class Flushables {
  private static final Logger logger
      = Logger.getLogger(Flushables.class.getName());
  private Flushables() {}

  
Flush a java.io.Flushable, with control over whether an IOException may be thrown.

If swallowIOException is true, then we don't rethrow IOException, but merely log it.

Parameters:
flushable the Flushable object to be flushed.
swallowIOException if true, don't propagate IO exceptions thrown by the flush method
Throws:
java.io.IOException if swallowIOException is false and java.io.Flushable.flush() throws an IOException.
See also:
com.google.common.io.Closeables.close(java.io.Closeable,boolean)
  public static void flush(Flushable flushableboolean swallowIOException)
      throws IOException {
    try {
      flushable.flush();
    } catch (IOException e) {
      if (swallowIOException) {
        .log(.,
            "IOException thrown while flushing Flushable."e);
      } else {
        throw e;
      }
    }
  }

  
Equivalent to calling flush(flushable, true), but with no IOException in the signature.

Parameters:
flushable the Flushable object to be flushed.
  public static void flushQuietly(Flushable flushable) {
    try {
      flush(flushabletrue);
    } catch (IOException e) {
      .log(."IOException should not have been thrown."e);
    }
  }
New to GrepCode? Check out our FAQ X