-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
override guava closeables to backport closeQuietly (#34)
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
hadoop-unit-commons/src/main/java/com/google/common/io/Closeables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Source code recreated from a .class file by IntelliJ IDEA | ||
// (powered by Fernflower decompiler) | ||
// | ||
|
||
package com.google.common.io; | ||
|
||
import com.google.common.annotations.Beta; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.annotation.Nullable; | ||
|
||
@Beta | ||
public final class Closeables { | ||
@VisibleForTesting | ||
static final Logger logger = Logger.getLogger(Closeables.class.getName()); | ||
|
||
private Closeables() { | ||
} | ||
|
||
public static void close(@Nullable Closeable closeable, boolean swallowIOException) throws IOException { | ||
if(closeable != null) { | ||
try { | ||
closeable.close(); | ||
} catch (IOException var3) { | ||
if(!swallowIOException) { | ||
throw var3; | ||
} | ||
|
||
logger.log(Level.WARNING, "IOException thrown while closing Closeable.", var3); | ||
} | ||
|
||
} | ||
} | ||
|
||
public static void closeQuietly(@Nullable InputStream inputStream) { | ||
try { | ||
close(inputStream, true); | ||
} catch (IOException var2) { | ||
throw new AssertionError(var2); | ||
} | ||
} | ||
|
||
public static void closeQuietly(@Nullable Reader reader) { | ||
try { | ||
close(reader, true); | ||
} catch (IOException var2) { | ||
throw new AssertionError(var2); | ||
} | ||
} | ||
|
||
//HACK : backport this method for hbase (disable table) | ||
/** | ||
* Equivalent to calling {@code close(closeable, true)}, but with no | ||
* IOException in the signature. | ||
* @param closeable the {@code Closeable} object to be closed, or null, in | ||
* which case this method does nothing | ||
*/ | ||
public static void closeQuietly(@Nullable Closeable closeable) { | ||
try { | ||
close(closeable, true); | ||
} catch (IOException e) { | ||
logger.log(Level.SEVERE, "IOException should not have been thrown.", e); | ||
} | ||
} | ||
} |