1313
1414import org .biojava .bio .structure .Structure ;
1515import org .biojava .bio .structure .StructureException ;
16- import org .biojava .bio .structure .align .ce .AbstractUserArgumentProcessor ;
16+ import org .biojava .bio .structure .align .util .UserConfiguration ;
17+ import org .slf4j .Logger ;
18+ import org .slf4j .LoggerFactory ;
1719
1820
1921
2527 */
2628public class LocalCacheStructureProvider implements StructureProvider {
2729
30+ private static final Logger logger = LoggerFactory .getLogger (LocalCacheStructureProvider .class );
31+
2832 FileParsingParameters params ;
2933
3034 String path ;
@@ -38,14 +42,9 @@ public LocalCacheStructureProvider(){
3842
3943 // set the path to cache files
4044
45+ UserConfiguration config = new UserConfiguration ();
4146
42- String defaultPath = System .getProperty (AbstractUserArgumentProcessor .PDB_DIR );
43- if ( defaultPath == null ) {
44- String property = "java.io.tmpdir" ;
45- defaultPath = System .getProperty (property );
46- }
47-
48- setPath (defaultPath );
47+ setPath (config .getPdbFilePath ());
4948
5049 }
5150
@@ -75,8 +74,7 @@ public Structure getStructureById(String pdbId) throws IOException {
7574 }
7675
7776 private PDBFileReader getPdbFilereader (){
78- PDBFileReader reader = new PDBFileReader ();
79- reader .setPath (path );
77+ PDBFileReader reader = new PDBFileReader (path );
8078 reader .setAutoFetch (true );
8179 reader .setFileParsingParameters (params );
8280 reader .setPdbDirectorySplit (isSplit );
@@ -134,42 +132,36 @@ private void downloadBiolUnit(String pdbId, File localFile) throws IOException{
134132
135133 String ur = String .format (u ,pdbId );
136134
137- System . out . println ("Fetching " + ur );
135+ logger . info ("Fetching " + ur );
138136
139137 // prepare destination
140- System .out .println ("writing to " + localFile );
141-
142- try {
143- URL url = new URL (ur );
144-
145- InputStream uStream = url .openStream ();
146- InputStream conn = new GZIPInputStream (uStream );
147-
148-
149- FileOutputStream outPut = new FileOutputStream (localFile );
150- GZIPOutputStream gzOutPut = new GZIPOutputStream (outPut );
151- PrintWriter pw = new PrintWriter (gzOutPut );
152-
153- BufferedReader fileBuffer = new BufferedReader (new InputStreamReader (conn ));
154- String line ;
155- while ((line = fileBuffer .readLine ()) != null ) {
156- pw .println (line );
157- }
158- pw .flush ();
159- pw .close ();
160-
161- outPut .flush ();
162- outPut .close ();
163- conn .close ();
164- uStream .close ();
165-
166- } catch (Exception e ){
167- System .err .println ("Problem while downloading PDB ID " + pdbId + " from " + ur );
168-
169- //e.printStackTrace();
170- throw new IOException ("Could not download biol. unit for PDB ID " + pdbId );
171-
138+ logger .info ("writing to " + localFile );
139+
140+
141+ URL url = new URL (ur );
142+
143+ InputStream uStream = url .openStream ();
144+ InputStream conn = new GZIPInputStream (uStream );
145+
146+
147+ FileOutputStream outPut = new FileOutputStream (localFile );
148+ GZIPOutputStream gzOutPut = new GZIPOutputStream (outPut );
149+ PrintWriter pw = new PrintWriter (gzOutPut );
150+
151+ BufferedReader fileBuffer = new BufferedReader (new InputStreamReader (conn ));
152+ String line ;
153+ while ((line = fileBuffer .readLine ()) != null ) {
154+ pw .println (line );
172155 }
156+ pw .flush ();
157+ pw .close ();
158+
159+ outPut .flush ();
160+ outPut .close ();
161+ conn .close ();
162+ uStream .close ();
163+
164+
173165 }
174166
175167 public void setFileParsingParameters (FileParsingParameters params ) {
0 commit comments