下面列出了java.util.jar.JarEntry#getTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void copyStream(InputStream inputStream, JarOutputStream jos, JarEntry ze, String pathName) {
try {
ZipEntry newEntry = new ZipEntry(pathName);
// Make sure there is date and time set.
if (ze.getTime() != -1) {
newEntry.setTime(ze.getTime());
newEntry.setCrc(ze.getCrc()); // If found set it into output file.
}
jos.putNextEntry(newEntry);
IOUtils.copy(inputStream, jos);
IOUtils.closeQuietly(inputStream);
} catch (Exception e) {
e.printStackTrace();
//throw new GradleException("copy stream exception", e);
//e.printStackTrace();
// logger.error("copy stream exception >>> " + pathName + " >>>" + e.getMessage());
}
}
private void copyStream(InputStream inputStream, JarOutputStream jos, JarEntry ze, String pathName) {
try {
ZipEntry newEntry = new ZipEntry(pathName);
// Make sure there is date and time set.
if (ze.getTime() != -1) {
newEntry.setTime(ze.getTime());
newEntry.setCrc(ze.getCrc()); // If found set it into output file.
}
jos.putNextEntry(newEntry);
IOUtils.copy(inputStream, jos);
IOUtils.closeQuietly(inputStream);
} catch (Exception e) {
//throw new GradleException("copy stream exception", e);
//e.printStackTrace();
logger.error("copy stream exception >>> " + pathName + " >>>" + e.getMessage());
}
}
public static long urlLastModified(URL url) throws URISyntaxException, IOException {
url = osgiToJar(url);
if ("jar".equalsIgnoreCase(url.getProtocol())) {
JarURLConnection jarEntryConn = (JarURLConnection)url.openConnection();
// Check that the jar file actually exists on the file system
File file = new File(jarEntryConn.getJarFileURL().getPath());
if (!file.exists()) throw new IOException("Unable to process JAR url. JAR file is missing: " + file);
try (JarFile jarFile = new JarFile(file)) {
// Automatically reject any JAR URL which does not contain a JAR entry
String jarEntryName = jarEntryConn.getEntryName();
if (jarEntryName == null) throw new IOException("Unsupported JAR url. Missing JAR entry: " + url);
JarEntry jarEntry = jarFile.getJarEntry(jarEntryName);
return jarEntry != null ? jarEntry.getTime() : -1;
}
}
return new File(url.toURI()).lastModified();
}
/**
* process one jar entry in an input jar file and optionally stores the entry in the output
* folder.
*
* @param jarFile the input jar file
* @param jarEntry the jar entry in the jarFile to process
* @param outputDir the output folder to use to copy/merge the entry in.
* @throws IOException
*/
private static void processJarEntry(JarFile jarFile, JarEntry jarEntry, File outputDir) throws IOException {
File outputFile = new File(outputDir, jarEntry.getName());
Action action = getAction(jarEntry.getName());
if (action == Action.COPY) {
if (!outputFile.getParentFile().exists() &&
!outputFile.getParentFile().mkdirs()) {
throw new RuntimeException("Cannot create directory " + outputFile.getParent());
}
if (!outputFile.exists() || outputFile.lastModified()
< jarEntry.getTime()) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = jarFile.getInputStream(jarEntry);
if (inputStream != null) {
outputStream = new BufferedOutputStream(
new FileOutputStream(outputFile));
ByteStreams.copy(inputStream, outputStream);
outputStream.flush();
} else {
throw new RuntimeException("Cannot copy " + jarEntry.getName());
}
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
}
}
}
/**
* 获取 Class 的修改时间
* @param clazz Class 对象
* @return 修改时间, 返回: -1 文件不存在 / 文件不是 Class 文件 / IO 异常
*/
public static long getClassModifyTime(Class clazz){
String location = getClassLocation(clazz);
if(location==null){
return -1;
}
String classNamePath = TEnv.classToResource(clazz);
try {
if(location.endsWith(".jar")) {
try(JarFile jarFile = new JarFile(location)) {
JarEntry jarEntry = jarFile.getJarEntry(classNamePath);
if(jarEntry!=null) {
return jarEntry.getTime();
}else{
return -1;
}
}
} else if (location.endsWith(File.separator)) {
File classFile = new File(location+classNamePath);
if(classFile!=null && classFile.exists()) {
return classFile.lastModified();
}else{
return -1;
}
} else {
return -1;
}
}catch (IOException e){
return -1;
}
}
public long lastModified() {
JarFile jarFile = getJarFile();
JarEntry jarEntry = jarFile.getJarEntry(getPath());
return jarEntry.getTime();
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName(toBundleName(baseName, locale), format);
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName0(toBundleName(baseName, locale), format);
if (resourceName == null) {
return result;
}
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName(toBundleName(baseName, locale), format);
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}
/**
* Determines if the expired <code>bundle</code> in the cache needs
* to be reloaded based on the loading time given by
* <code>loadTime</code> or some other criteria. The method returns
* <code>true</code> if reloading is required; <code>false</code>
* otherwise. <code>loadTime</code> is a millisecond offset since
* the <a href="Calendar.html#Epoch"> <code>Calendar</code>
* Epoch</a>.
*
* The calling <code>ResourceBundle.getBundle</code> factory method
* calls this method on the <code>ResourceBundle.Control</code>
* instance used for its current invocation, not on the instance
* used in the invocation that originally loaded the resource
* bundle.
*
* <p>The default implementation compares <code>loadTime</code> and
* the last modified time of the source data of the resource
* bundle. If it's determined that the source data has been modified
* since <code>loadTime</code>, <code>true</code> is
* returned. Otherwise, <code>false</code> is returned. This
* implementation assumes that the given <code>format</code> is the
* same string as its file suffix if it's not one of the default
* formats, <code>"java.class"</code> or
* <code>"java.properties"</code>.
*
* @param baseName
* the base bundle name of the resource bundle, a
* fully qualified class name
* @param locale
* the locale for which the resource bundle
* should be instantiated
* @param format
* the resource bundle format to be loaded
* @param loader
* the <code>ClassLoader</code> to use to load the bundle
* @param bundle
* the resource bundle instance that has been expired
* in the cache
* @param loadTime
* the time when <code>bundle</code> was loaded and put
* in the cache
* @return <code>true</code> if the expired bundle needs to be
* reloaded; <code>false</code> otherwise.
* @exception NullPointerException
* if <code>baseName</code>, <code>locale</code>,
* <code>format</code>, <code>loader</code>, or
* <code>bundle</code> is <code>null</code>
*/
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader,
ResourceBundle bundle, long loadTime) {
if (bundle == null) {
throw new NullPointerException();
}
if (format.equals("java.class") || format.equals("java.properties")) {
format = format.substring(5);
}
boolean result = false;
try {
String resourceName = toResourceName(toBundleName(baseName, locale), format);
URL url = loader.getResource(resourceName);
if (url != null) {
long lastModified = 0;
URLConnection connection = url.openConnection();
if (connection != null) {
// disable caches to get the correct data
connection.setUseCaches(false);
if (connection instanceof JarURLConnection) {
JarEntry ent = ((JarURLConnection)connection).getJarEntry();
if (ent != null) {
lastModified = ent.getTime();
if (lastModified == -1) {
lastModified = 0;
}
}
} else {
lastModified = connection.getLastModified();
}
}
result = lastModified >= loadTime;
}
} catch (NullPointerException npe) {
throw npe;
} catch (Exception e) {
// ignore other exceptions
}
return result;
}