Skip to content

Commit e924815

Browse files
committed
ABITracer Constructor with URL
1 parent cb65133 commit e924815

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

biojava-core/src/main/java/org/biojava/nbio/core/sequence/io/ABITrace.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.awt.Color;
3333
import java.awt.Graphics2D;
3434
import java.awt.image.BufferedImage;
35+
import java.net.URL;
36+
import java.io.InputStream;
3537

3638
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
3739
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
@@ -96,6 +98,28 @@ public ABITrace(File ABIFile) throws IOException {
9698
initData(bytes);
9799
}
98100

101+
/**
102+
* The URL constructor opens an ABI file from any URL.
103+
* @param ABIFile is a <code>java.net.URL</code> for an ABI trace file.
104+
* @throws IOException if there is a problem reading from the URL.
105+
* @throws IllegalArgumentException if the URL does not contain a valid ABI file.
106+
*/
107+
public ABITrace( URL ABIFile ) throws IOException
108+
{
109+
byte[] bytes = null;
110+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
111+
InputStream is = ABIFile.openStream();
112+
BufferedInputStream bis = new BufferedInputStream(is);
113+
int b;
114+
while ((b = bis.read()) >= 0)
115+
{
116+
baos.write(b);
117+
}
118+
bis.close(); is.close(); baos.close();
119+
bytes = baos.toByteArray();
120+
initData(bytes);
121+
}
122+
99123
/**
100124
* The <code>byte[]</code> constructor parses an ABI file represented as a byte array.
101125
*

biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package org.biojava.nbio.core.sequence.io;
2323

2424
import java.io.File;
25+
import java.net.URL;
2526
import org.junit.*;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
@@ -50,12 +51,23 @@ public void tearDown() {
5051
}
5152

5253
/**
53-
* Test of process method, of class ABITracer.
54+
* Test of local method, of class ABITracer.
5455
*/
5556
@Test
56-
public void testProcess() throws Exception {
57-
logger.info("process");
57+
public void testURL() throws Exception {
58+
URL url = new URL("https://github.com/biopython/biopython/blob/master/Tests/Abi/3730.ab1");
59+
Assert.assertNotNull(url);
60+
ABITrace tracer = new ABITrace(url);
61+
Assert.assertNotNull(tracer);
62+
}
63+
64+
/**
65+
* Test of local method, of class ABITracer.
66+
*/
67+
@Test
68+
public void testLocal() throws Exception {
5869
File file = new File("/3730.ab1");
70+
Assert.assertNotNull(file);
5971
ABITrace tracer = new ABITrace(file);
6072
Assert.assertNotNull(tracer);
6173
}

0 commit comments

Comments
 (0)