Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
JavaDock
  • Loading branch information
aalhossary committed Feb 21, 2022
commit aed24fad9664484780dce00fb3f073921e34ae36
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ public static void downloadFile(URL url, File destination) throws IOException {

}

/**
* Creates validation files beside a file to be downloaded.<br>
* Whenever possible, for a <code>file.ext</code> file, it creates
* <code>file.ext.size</code> and <code>file.hash</code> for in the same
* folder where <code>file.ext</code> exists.
* If the file connection size could not be deduced from the URL, no size file is created.
* If <code>hashURL</code> is <code>null</code>, no hash file is created.
* @param url the remote file URL to download
* @param localDestination the local file to download into
* @param hashURL the URL of the hash file to download. Can be <code>null</code>.
*/
public static void createValidationFiles(URL url, File localDestination, URL hashURL){
try {
URLConnection resourceConnection = url.openConnection();
Expand All @@ -173,6 +184,19 @@ public static void createValidationFiles(URL url, File localDestination, URL has
logger.warn("could not open connection to resource file due to exception", e);
Comment thread
aalhossary marked this conversation as resolved.
Outdated
}
}
/**
* Creates validation files beside a file to be downloaded.<br>
* Whenever possible, for a <code>file.ext</code> file, it creates
* <code>file.ext.size</code> and <code>file.hash</code> for in the same
* folder where <code>file.ext</code> exists.
* If the file connection size could not be deduced from the resourceUrlConnection
* {@link URLConnection}, no size file is created.
* If <code>hashURL</code> is <code>null</code>, no hash file is created.
* @param resourceUrlConnection the remote file URLConnection to download
* @param localDestination the local file to download into
* @param hashURL the URL of the hash file to download. Can be <code>null</code>.
* @since 6.0.6
*/
public static void createValidationFiles(URLConnection resourceUrlConnection, File localDestination, URL hashURL){
long size = resourceUrlConnection.getContentLengthLong();
if(size != -1) {
Expand All @@ -197,6 +221,20 @@ public static void createValidationFiles(URLConnection resourceUrlConnection, Fi
}
}

/**
* Validate a local file based on pre-existing metadata files for size and hash.<br>
* If the passed in <code>localFile</code> parameter is a file named <code>file.ext</code>, the function searches in the same folder for:
* <ul>
* <li><code>file.ext.size</code>: if found, it compares the size stored in it to the length of <code>localFile</code> (in bytes).</li>
* <li><code>file.ext.hash</code>: if found, it compares the size stored in it to the hash code of <code>localFile</code>.</li>
* </ul>
* If any of these comparisons fail, the function returns <code>false</code>. otherwise it returns true.
* <p>
* This function does not implement hash code verification yet.
* @param localFile The file to validate
* @return <code>false</code> if any of the size or hash code metadata files exists but its contents does not match the expected value in the file, <code>true'</code> otherwise.
* @since 6.0.6
*/
public static boolean validateFile(File localFile) {
File sizeFile = new File(localFile.getParentFile(), localFile.getName()+".size");
if(sizeFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ private boolean domainsAvailable() {
}

/**
* Downloads the domains file, overwriting any existing file
* @throws IOException
* Downloads the domains file +/- its validation metadata, overwriting any existing file
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
*/
private void downloadDomains() throws IOException {
domainsFileLock.writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public Structure getStructureById(PdbId pdbId) throws IOException {
* for direct parsing.
* @param pdbId
* @return
* @throws IOException
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
*/
protected InputStream getInputStream(PdbId pdbId) throws IOException{

Expand All @@ -388,7 +388,7 @@ protected InputStream getInputStream(PdbId pdbId) throws IOException{
*
* Used to pre-fetch large numbers of structures.
* @param pdbId
* @throws IOException
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
*/
public void prefetchStructure(String pdbId) throws IOException {

Expand Down Expand Up @@ -530,14 +530,14 @@ protected File downloadStructure(PdbId pdbId) throws IOException {
}

/**
* Download a file from the ftp server, replacing any existing files if needed
* Download a file from the ftp server +/- its validation metadata, replacing any existing files if needed
* @param pdbId PDB ID
* @param pathOnServer Path on the FTP server, e.g. data/structures/divided/pdb
* @param obsolete Whether or not file should be saved to the obsolete location locally
* @param existingFile if not null and checkServerFileDate is true, the last modified date of the
* server file and this file will be compared to decide whether to download or not
* @return
* @throws IOException
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
*/
private File downloadStructure(PdbId pdbId, String pathOnServer, boolean obsolete, File existingFile)
throws IOException{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,12 @@ protected void downloadComFile() throws FileNotFoundException, IOException{
throw new IOException("Unable to download SCOP .com file",exception);
}

/**
* Downloads the SCOP installation file +/- its validation metadata files.
* @param remoteURL The remote file to download
* @param localFile the local file to download to
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
*/
protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException{
logger.info("Downloading " + remoteURL + " to: " + localFile);
FileDownloadUtils.createValidationFiles(remoteURL, localFile, null);
Expand Down