/** * Obtains the URL for the Resource and opens the stream, wrapped by a BufferedInputStream. */ @Override public InputStream openStream() throws IOException { URL url = toURL(); if (url == null) { return null; } if ("jar".equals(url.getProtocol())){ // TAP5-2448: make sure that the URL does not reference a directory String urlAsString = url.toString(); int indexOfExclamationMark = urlAsString.indexOf('!'); String resourceInJar = urlAsString.substring(indexOfExclamationMark + 2); URL directoryResource = Thread.currentThread().getContextClassLoader().getResource(resourceInJar + "/"); boolean isDirectory = directoryResource != null && "jar".equals(directoryResource.getProtocol()); if (isDirectory) { throw new IOException("Cannot open a stream for a resource that references a directory inside a JAR file (" + url + ")."); } } return new BufferedInputStream(url.openStream()); }
/** * Obtains the URL for the Resource and opens the stream, wrapped by a BufferedInputStream. */ @Override public InputStream openStream() throws IOException { URL url = toURL(); if (url == null) { return null; } if ("jar".equals(url.getProtocol())){ // TAP5-2448: make sure that the URL does not reference a directory String urlAsString = url.toString(); int indexOfExclamationMark = urlAsString.indexOf('!'); String resourceInJar = urlAsString.substring(indexOfExclamationMark + 2); URL directoryResource = Thread.currentThread().getContextClassLoader().getResource(resourceInJar + "/"); boolean isDirectory = directoryResource != null && "jar".equals(directoryResource.getProtocol()); if (isDirectory) { throw new IOException("Cannot open a stream for a resource that references a directory inside a JAR file (" + url + ")."); } } return new BufferedInputStream(url.openStream()); }
private void computeExists() { try { upgradeReadLockToWriteLock(); if (!existsComputed) { exists = toURL() != null; existsComputed = true; } } finally { downgradeWriteLockToReadLock(); } }
private void computeExists() { try { upgradeReadLockToWriteLock(); if (!existsComputed) { exists = toURL() != null; existsComputed = true; } } finally { downgradeWriteLockToReadLock(); } }