Search in sources :

Example 6 with ClosingFileReader

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;
}
Also used : ClosingFileReader(com.ibm.dtfj.corereaders.ClosingFileReader) File(java.io.File)

Example 7 with ClosingFileReader

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());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) ClosingFileReader(com.ibm.dtfj.corereaders.ClosingFileReader) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

ClosingFileReader (com.ibm.dtfj.corereaders.ClosingFileReader)7 IOException (java.io.IOException)4 ICoreFileReader (com.ibm.dtfj.corereaders.ICoreFileReader)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 NewAixDump (com.ibm.dtfj.corereaders.NewAixDump)2 MemoryAccessException (com.ibm.dtfj.corereaders.MemoryAccessException)1 MemoryRange (com.ibm.dtfj.corereaders.MemoryRange)1 NewElfDump (com.ibm.dtfj.corereaders.NewElfDump)1 ResourceReleaser (com.ibm.dtfj.corereaders.ResourceReleaser)1 XMLIndexReader (com.ibm.jvm.j9.dump.indexsupport.XMLIndexReader)1 XMLInputStream (com.ibm.jvm.j9.dump.indexsupport.XMLInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1