Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More fiddling with suddenly closed streams (apparently jena closes st…
…reams in LangBase:44)
- Loading branch information
Showing
2 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ansa-rdf-common/src/main/java/net/sansa_stack/rdf/common/InputStreamWithCloseLogging.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,34 @@ | ||
package net.sansa_stack.rdf.common; | ||
|
||
import org.apache.commons.io.input.ProxyInputStream; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
/** Util class to debug a stream already closed exception */ | ||
public class InputStreamWithCloseLogging | ||
extends ProxyInputStream | ||
{ | ||
protected Consumer<? super Throwable> stackTraceConsumer; | ||
|
||
public InputStreamWithCloseLogging(InputStream proxy, Consumer<? super Throwable> stackTraceConsumer) { | ||
super(proxy); | ||
this.stackTraceConsumer = stackTraceConsumer; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
stackTraceConsumer.accept(new Throwable()); | ||
super.close(); | ||
} | ||
|
||
/** Convenience method for e.g. .wrap(inputStream, ExceptionUtils::getFullStackTrace, logger::info) */ | ||
public static InputStream wrap(InputStream proxy, Function<? super Throwable, String> toString, Consumer<? super String> logger) { | ||
return new InputStreamWithCloseLogging(proxy, t -> { | ||
String str = toString.apply(t); | ||
logger.accept(str); | ||
}); | ||
} | ||
} |
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