public class MirroredInputStream extends InputStream
The file mirrored is only downloaded if it has been more than 7 days since last download
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_MAXTIME |
(package private) File |
file |
(package private) InputStream |
fs |
Constructor and Description |
---|
MirroredInputStream(String name) |
MirroredInputStream(String name,
long maxTime) |
MirroredInputStream(String name,
String destDir) |
MirroredInputStream(String name,
String destDir,
long maxTime)
Get an inputstream from a given filename, url or internal resource.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
private File |
checkLocal(URL url,
String destDir,
long maxTime) |
static void |
cleanup(String name) |
static void |
cleanup(String name,
String destDir) |
void |
close() |
static HttpURLConnection |
connectFollowingRedirect(URL downloadUrl)
Opens a connection for downloading a resource.
|
private Pair<String,InputStream> |
findZipEntryImpl(String extension,
String namepart) |
InputStream |
findZipEntryInputStream(String extension,
String namepart)
Like
findZipEntryPath(java.lang.String, java.lang.String) , but returns the corresponding InputStream. |
String |
findZipEntryPath(String extension,
String namepart)
Looks for a certain entry inside a zip file and returns the entry path.
|
File |
getFile() |
private static String |
getPrefKey(URL url,
String destDir)
get preference key to store the location and age of the cached file.
2 resources that point to the same url, but that are to be stored in different
directories will not share a cache file.
|
InputStream |
getZipEntry(String extension,
String namepart)
Deprecated.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
long |
skip(long n) |
mark, markSupported, reset
InputStream fs
public static final long DEFAULT_MAXTIME
public MirroredInputStream(String name) throws IOException
IOException
public MirroredInputStream(String name, long maxTime) throws IOException
IOException
public MirroredInputStream(String name, String destDir) throws IOException
IOException
public MirroredInputStream(String name, String destDir, long maxTime) throws IOException
name
- can be
- relative or absolute file name
- file:///SOME/FILE the same as above
- resource://SOME/FILE file from the classpath (usually in the current *.jar)
- http://... a url. It will be cached on disk.destDir
- the destination directory for the cache file. only applies for urls.maxTime
- the maximum age of the cache file (in seconds)IOException
- when the resource with the given name could not be retrievedpublic String findZipEntryPath(String extension, String namepart)
extension
. If more than one files have this
extension, the last file whose name includes namepart
is opened.extension
- the extension of the file we're looking fornamepart
- the name partpublic InputStream findZipEntryInputStream(String extension, String namepart)
findZipEntryPath(java.lang.String, java.lang.String)
, but returns the corresponding InputStream.@Deprecated public InputStream getZipEntry(String extension, String namepart)
private Pair<String,InputStream> findZipEntryImpl(String extension, String namepart)
private static String getPrefKey(URL url, String destDir)
private File checkLocal(URL url, String destDir, long maxTime) throws IOException
IOException
public static HttpURLConnection connectFollowingRedirect(URL downloadUrl) throws MalformedURLException, IOException
Manually follows redirects because
HttpURLConnection.setFollowRedirects(boolean)
fails if the redirect
is going from a http to a https URL, see bug report.
This can causes problems when downloading from certain GitHub URLs.
downloadUrl
- The resource URL to downloadMalformedURLException
- If a redirected URL is wrongIOException
- If any I/O operation goes wrongpublic int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException