Merge pull request #23813 from izeye
* pr/23813: Polish contribution Polish AbstractResource Closes gh-23813
This commit is contained in:
commit
9c1a0d32be
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -25,6 +25,7 @@ import java.net.URISyntaxException;
|
|||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
|
@ -60,10 +61,7 @@ public abstract class AbstractResource implements Resource {
|
|||
return getFile().exists();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not retrieve File for existence check of " + getDescription(), ex);
|
||||
}
|
||||
debug(() -> "Could not retrieve File for existence check of " + getDescription(), ex);
|
||||
}
|
||||
}
|
||||
// Fall back to stream existence: can we open the stream?
|
||||
|
|
@ -72,10 +70,7 @@ public abstract class AbstractResource implements Resource {
|
|||
return true;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not retrieve InputStream for existence check of " + getDescription(), ex);
|
||||
}
|
||||
debug(() -> "Could not retrieve InputStream for existence check of " + getDescription(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -174,10 +169,7 @@ public abstract class AbstractResource implements Resource {
|
|||
is.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not close content-length InputStream for " + getDescription(), ex);
|
||||
}
|
||||
debug(() -> "Could not close content-length InputStream for " + getDescription(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -258,4 +250,11 @@ public abstract class AbstractResource implements Resource {
|
|||
return getDescription();
|
||||
}
|
||||
|
||||
private void debug(Supplier<String> message, Throwable ex) {
|
||||
Log logger = LogFactory.getLog(getClass());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(message.get(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue