use of com.ibm.dtfj.corereaders.ClosingFileReader in project openj9 by eclipse.
the class Builder method openFile.
public ClosingFileReader openFile(String filename) throws IOException {
// this is where the resolving agent comes in handy. Not only will it look on the filesystem but it is also free to look into jars and other interesting containers where we can expect to find things
File foundFile = _resolvingAgent.findFileWithFullPath(filename);
ClosingFileReader reader = new ClosingFileReader(foundFile);
_fileTracker.addFile(reader);
return reader;
}
use of com.ibm.dtfj.corereaders.ClosingFileReader in project openj9 by eclipse.
the class Main method createZipFromFileNames.
private static void createZipFromFileNames(String zipFileName, Iterator fileNames, Builder fileResolver) throws Exception {
report("Creating archive file: " + zipFileName);
ZipOutputStream zip;
try {
Set filesInZip = new HashSet();
zip = new ZipOutputStream(new FileOutputStream(zipFileName));
byte[] buffer = new byte[ZIP_BUFFER_SIZE];
while (fileNames.hasNext()) {
String name = (String) fileNames.next();
try {
ClosingFileReader in = fileResolver.openFile(name);
boolean mvsfile = in.isMVSFile();
String absolute = in.getAbsolutePath();
if (absolute.equals(new File(name).getAbsolutePath()) || mvsfile == true) {
report("Adding \"" + name + "\"");
} else {
report("Adding \"" + name + "\" (found at \"" + absolute + "\")");
}
if (mvsfile) {
// mvs files exist in a different filespace, so read the file from
// mvs and insert it into the zip.
zip.putNextEntry(new ZipEntry(name));
filesInZip.add(name);
copy(in, zip, buffer);
} else {
// Guard against two names in fileNames mapping to the same absolute path.
if (!filesInZip.contains(absolute)) {
// note that we can't just use the file name, we have to use
// the full path since they may share a name
// note also that we will use the original path and not the
// path with a virtual root prepended to it
InputStream fileStream = in.streamFromFile();
ZipEntry zipEntry = new ZipEntry(absolute);
filesInZip.add(absolute);
zipEntry.setTime((new File(absolute)).lastModified());
zip.putNextEntry(zipEntry);
copy(fileStream, zip, buffer);
fileStream.close();
}
}
} catch (FileNotFoundException e1) {
report("Warning: Could not find file \"" + name + "\" for inclusion in archive");
} catch (IOException e) {
// chain the exception
throw new Exception("Failure adding file " + name + " to archive", e);
} finally {
zip.closeEntry();
}
}
try {
zip.close();
} catch (IOException e) {
throw new Exception("Failure closing archive file (" + zipFileName + ") : " + e.getMessage());
}
} catch (FileNotFoundException e1) {
throw new Exception("Could not find archive file to output to: " + e1.getMessage());
}
}
Aggregations