Skip to content

Commit b805538

Browse files
committed
add method addFile(URL)
1 parent b2e17e2 commit b805538

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/de/inetsoftware/jwebassembly/JWebAssembly.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import java.io.BufferedInputStream;
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.File;
21-
import java.io.FileInputStream;
2221
import java.io.FileOutputStream;
2322
import java.io.IOException;
2423
import java.io.OutputStream;
24+
import java.net.MalformedURLException;
25+
import java.net.URL;
2526
import java.util.ArrayList;
2627
import java.util.List;
2728

@@ -39,7 +40,7 @@
3940
*/
4041
public class JWebAssembly {
4142

42-
private List<File> classFiles = new ArrayList<File>();
43+
private List<URL> classFiles = new ArrayList<>();
4344

4445
/**
4546
* Create a instance.
@@ -54,6 +55,20 @@ public JWebAssembly() {
5455
* the file
5556
*/
5657
public void addFile( @Nonnull File classFile ) {
58+
try {
59+
classFiles.add( classFile.toURI().toURL() );
60+
} catch( MalformedURLException ex ) {
61+
throw new IllegalArgumentException( ex );
62+
}
63+
}
64+
65+
/**
66+
* Add a classFile to compile
67+
*
68+
* @param classFile
69+
* the file
70+
*/
71+
public void addFile( @Nonnull URL classFile ) {
5772
classFiles.add( classFile );
5873
}
5974

@@ -142,8 +157,8 @@ public void compileToBinary( OutputStream output ) throws WasmException {
142157
* if any conversion error occurs
143158
*/
144159
private void compile( ModuleWriter writer ) throws IOException, WasmException {
145-
for( File file : classFiles ) {
146-
ClassFile classFile = new ClassFile( new BufferedInputStream( new FileInputStream( file ) ) );
160+
for( URL url : classFiles ) {
161+
ClassFile classFile = new ClassFile( new BufferedInputStream( url.openStream() ) );
147162
writer.write( classFile );
148163
}
149164
}

0 commit comments

Comments
 (0)