File tree Expand file tree Collapse file tree 3 files changed +48
-49
lines changed
biojava-genome/src/main/java/org/biojava/nbio/genome/parsers Expand file tree Collapse file tree 3 files changed +48
-49
lines changed Original file line number Diff line number Diff line change @@ -62,27 +62,27 @@ public static FeatureList read(String filename) throws IOException {
6262 logger .info ("Reading: {}" , filename );
6363
6464 FeatureList features = new FeatureList ();
65- BufferedReader br = new BufferedReader (new FileReader (filename ));
65+ try ( BufferedReader br = new BufferedReader (new FileReader (filename ))) {
6666
67- String s ;
68- for (s = br .readLine (); null != s ; s = br .readLine ()) {
69- s = s .trim ();
67+ String s ;
68+ for (s = br .readLine (); null != s ; s = br .readLine ()) {
69+ s = s .trim ();
7070
71- if (s .length () > 0 ) {
72- if (s .charAt (0 ) == '#' ) {
73- //ignore comment lines
74- } else {
71+ if (s .length () > 0 ) {
72+ if (s .charAt (0 ) == '#' ) {
73+ //ignore comment lines
74+ } else {
7575
76- FeatureI f = parseLine (s );
77- if (f != null ) {
78- features .add (f );
76+ FeatureI f = parseLine (s );
77+ if (f != null ) {
78+ features .add (f );
79+ }
7980 }
8081 }
82+
8183 }
8284
8385 }
84-
85- br .close ();
8686 return features ;
8787 }
8888
Original file line number Diff line number Diff line change @@ -63,27 +63,27 @@ public static FeatureList read(String filename) throws IOException {
6363 logger .info ("Reading: {}" , filename );
6464
6565 FeatureList features = new FeatureList ();
66- BufferedReader br = new BufferedReader (new FileReader (filename ));
66+ try ( BufferedReader br = new BufferedReader (new FileReader (filename ))) {
6767
68- String s ;
69- for (s = br .readLine (); null != s ; s = br .readLine ()) {
70- s = s .trim ();
68+ String s ;
69+ for (s = br .readLine (); null != s ; s = br .readLine ()) {
70+ s = s .trim ();
7171
72- if (s .length () > 0 ) {
73- if (s .charAt (0 ) == '#' ) {
74- //ignore comment lines
75- } else {
72+ if (s .length () > 0 ) {
73+ if (s .charAt (0 ) == '#' ) {
74+ //ignore comment lines
75+ } else {
7676
77- FeatureI f = parseLine (s );
78- if (f != null ) {
79- features .add (f );
77+ FeatureI f = parseLine (s );
78+ if (f != null ) {
79+ features .add (f );
80+ }
8081 }
8182 }
83+
8284 }
8385
8486 }
85-
86- br .close ();
8787 return features ;
8888 }
8989
Original file line number Diff line number Diff line change @@ -371,32 +371,31 @@ public static void main(String[] args) throws Exception {
371371 logger .info ("Resulting fasta data will be written in stdout." );
372372 return ;
373373 }
374- TwoBitParser p = new TwoBitParser (new File (args [0 ]));
375- if (args .length ==1 ) {
376- String [] names = p .getSequenceNames ();
377- for (int i =0 ;i <names .length ;i ++) {
378- p .setCurrentSequence (names [i ]);
379- p .printFastaSequence ();
374+ try (TwoBitParser p = new TwoBitParser (new File (args [0 ]))) {
375+ if (args .length == 1 ) {
376+ String [] names = p .getSequenceNames ();
377+ for (int i = 0 ; i < names .length ; i ++) {
378+ p .setCurrentSequence (names [i ]);
379+ p .printFastaSequence ();
380+ p .close ();
381+ }
382+ } else {
383+ String name = args [1 ];
384+ p .setCurrentSequence (name );
385+ if (args .length > 2 ) {
386+ long start = Long .parseLong (args [2 ]);
387+ p .skip (start );
388+ }
389+ if (args .length > 3 ) {
390+ long len = Long .parseLong (args [3 ]);
391+ p .printFastaSequence (len );
392+ } else {
393+ p .printFastaSequence ();
394+ }
380395 p .close ();
381396 }
397+ p .closeParser ();
382398 }
383- else {
384- String name = args [1 ];
385- p .setCurrentSequence (name );
386- if (args .length >2 ) {
387- long start = Long .parseLong (args [2 ]);
388- p .skip (start );
389- }
390- if (args .length >3 ) {
391- long len = Long .parseLong (args [3 ]);
392- p .printFastaSequence (len );
393- }
394- else {
395- p .printFastaSequence ();
396- }
397- p .close ();
398- }
399- p .closeParser ();
400399 }
401400}
402401
You can’t perform that action at this time.
0 commit comments