Commit dd3fb0f7 authored by Lukáš Marek's avatar Lukáš Marek
Browse files

CompilerStub implemented

parent b42916f8
package ch.usi.dag.disl;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class CompilerStub {
byte [] compile(String fileName) {
// thx: http://www.exampledepot.com/egs/java.io/File2ByteArray.html
public byte [] readFileAsBytes(String fileName) throws IOException {
// Create input stream
File file = new File(fileName);
InputStream is = new FileInputStream(file);
byte[] bytes = null;
try {
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
throw new IOException(
"File " + file.getName() + " is too large");
}
// Create the byte array to hold the data
bytes = new byte[(int) length];
// Read in the bytes
int offset = 0;
while (offset < bytes.length) {
int numRead = is.read(bytes, offset, bytes.length - offset);
// Input is expected but -1 (end of file) was returned
if(numRead < 0) {
throw new IOException("Could not completely read file "
+ file.getName());
}
offset += numRead;
}
}
finally {
// Close the input stream...
is.close();
}
// ... and return bytes
return bytes;
}
byte [] compile(String fileName) throws IOException {
// TODO! read class from file instead of compiling
return null;
// read class from file instead of compiling
return readFileAsBytes(fileName);
}
}
package ch.usi.dag.disl;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
......@@ -24,7 +25,7 @@ public class DiSLDriver implements Instrumentation {
List<Analyzer> analyzers = new LinkedList<Analyzer>();
Weaver weaver;
public DiSLDriver() {
public DiSLDriver() throws IOException {
super();
String classesToCompile = System.getProperty(PROP_DISL_CLASSES);
......
......@@ -23,7 +23,7 @@ public class Parser {
public List<Analyzer> getAnalyzers() {
// TODO! implement
// TODO implement
return null;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment