Skip to content

Commit aed24fa

Browse files
committed
JavaDock
1 parent b8e69a4 commit aed24fa

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ public static void downloadFile(URL url, File destination) throws IOException {
165165

166166
}
167167

168+
/**
169+
* Creates validation files beside a file to be downloaded.<br>
170+
* Whenever possible, for a <code>file.ext</code> file, it creates
171+
* <code>file.ext.size</code> and <code>file.hash</code> for in the same
172+
* folder where <code>file.ext</code> exists.
173+
* If the file connection size could not be deduced from the URL, no size file is created.
174+
* If <code>hashURL</code> is <code>null</code>, no hash file is created.
175+
* @param url the remote file URL to download
176+
* @param localDestination the local file to download into
177+
* @param hashURL the URL of the hash file to download. Can be <code>null</code>.
178+
*/
168179
public static void createValidationFiles(URL url, File localDestination, URL hashURL){
169180
try {
170181
URLConnection resourceConnection = url.openConnection();
@@ -173,6 +184,19 @@ public static void createValidationFiles(URL url, File localDestination, URL has
173184
logger.warn("could not open connection to resource file due to exception", e);
174185
}
175186
}
187+
/**
188+
* Creates validation files beside a file to be downloaded.<br>
189+
* Whenever possible, for a <code>file.ext</code> file, it creates
190+
* <code>file.ext.size</code> and <code>file.hash</code> for in the same
191+
* folder where <code>file.ext</code> exists.
192+
* If the file connection size could not be deduced from the resourceUrlConnection
193+
* {@link URLConnection}, no size file is created.
194+
* If <code>hashURL</code> is <code>null</code>, no hash file is created.
195+
* @param resourceUrlConnection the remote file URLConnection to download
196+
* @param localDestination the local file to download into
197+
* @param hashURL the URL of the hash file to download. Can be <code>null</code>.
198+
* @since 6.0.6
199+
*/
176200
public static void createValidationFiles(URLConnection resourceUrlConnection, File localDestination, URL hashURL){
177201
long size = resourceUrlConnection.getContentLengthLong();
178202
if(size != -1) {
@@ -197,6 +221,20 @@ public static void createValidationFiles(URLConnection resourceUrlConnection, Fi
197221
}
198222
}
199223

224+
/**
225+
* Validate a local file based on pre-existing metadata files for size and hash.<br>
226+
* If the passed in <code>localFile</code> parameter is a file named <code>file.ext</code>, the function searches in the same folder for:
227+
* <ul>
228+
* <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>
229+
* <li><code>file.ext.hash</code>: if found, it compares the size stored in it to the hash code of <code>localFile</code>.</li>
230+
* </ul>
231+
* If any of these comparisons fail, the function returns <code>false</code>. otherwise it returns true.
232+
* <p>
233+
* This function does not implement hash code verification yet.
234+
* @param localFile The file to validate
235+
* @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.
236+
* @since 6.0.6
237+
*/
200238
public static boolean validateFile(File localFile) {
201239
File sizeFile = new File(localFile.getParentFile(), localFile.getName()+".size");
202240
if(sizeFile.exists()) {

biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodInstallation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ private boolean domainsAvailable() {
395395
}
396396

397397
/**
398-
* Downloads the domains file, overwriting any existing file
399-
* @throws IOException
398+
* Downloads the domains file +/- its validation metadata, overwriting any existing file
399+
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
400400
*/
401401
private void downloadDomains() throws IOException {
402402
domainsFileLock.writeLock().lock();

biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public Structure getStructureById(PdbId pdbId) throws IOException {
362362
* for direct parsing.
363363
* @param pdbId
364364
* @return
365-
* @throws IOException
365+
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
366366
*/
367367
protected InputStream getInputStream(PdbId pdbId) throws IOException{
368368

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

@@ -530,14 +530,14 @@ protected File downloadStructure(PdbId pdbId) throws IOException {
530530
}
531531

532532
/**
533-
* Download a file from the ftp server, replacing any existing files if needed
533+
* Download a file from the ftp server +/- its validation metadata, replacing any existing files if needed
534534
* @param pdbId PDB ID
535535
* @param pathOnServer Path on the FTP server, e.g. data/structures/divided/pdb
536536
* @param obsolete Whether or not file should be saved to the obsolete location locally
537537
* @param existingFile if not null and checkServerFileDate is true, the last modified date of the
538538
* server file and this file will be compared to decide whether to download or not
539539
* @return
540-
* @throws IOException
540+
* @throws IOException in cases of file I/O, including failure to download a healthy (non-corrupted) file.
541541
*/
542542
private File downloadStructure(PdbId pdbId, String pathOnServer, boolean obsolete, File existingFile)
543543
throws IOException{

biojava-structure/src/main/java/org/biojava/nbio/structure/scop/ScopInstallation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,12 @@ protected void downloadComFile() throws FileNotFoundException, IOException{
739739
throw new IOException("Unable to download SCOP .com file",exception);
740740
}
741741

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

0 commit comments

Comments
 (0)