Search in sources :

Example 1 with IInArchive

use of com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive in project mucommander by mucommander.

the class SevenZipArchiveFile method getEntryInputStream.

// ////////////////////////////////////////
// AbstractROArchiveFile implementation //
// ////////////////////////////////////////
@Override
public InputStream getEntryInputStream(final ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException {
    final IInArchive sevenZipFile = openSevenZipFile();
    /*		ByteArrayOutputStream os = new ByteArrayOutputStream(1024);

//		threadPool.execute(new Runnable() {
//			public void run() {
//		        BufferedOutputStream bufferedOut = new BufferedOutputStream(out);
		        try {
		        	int arrays []  = new int[1];
		            for(int i = 0 ; i < sevenZipFile.size() ; i++) {
//		                	System.out.println("check " + sevenZipFile.getEntry(i).getName());
		                if (entry.getPath().equals(sevenZipFile.getEntry(i).getName())) {
		                	System.out.println("entry.getPath = " + entry.getPath() + ", sevenZipFile.getEntry(i).getName() " + sevenZipFile.getEntry(i).getName());
		                    arrays[0] = i;
		                    break;
		                }
		            }
		        	
					MuArchiveExtractCallback extractCallbackSpec = new MuArchiveExtractCallback(os);//, entry.getPath());
			        extractCallbackSpec.Init(sevenZipFile);
			        try {
			        	sevenZipFile.Extract(arrays, 1, IInArchive.NExtract_NAskMode_kExtract , extractCallbackSpec);
			        }
			        catch (Exception e) {
			        	e.printStackTrace();
//			        	return;
			        }
//			        sevenZipFile.Extract(null, -1, IInArchive.NExtract_NAskMode_kExtract , extractCallbackSpec);
			        try
			        {
			        Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second)
			        }
			        catch(InterruptedException e)
			        {
			        e.printStackTrace();
			        }
			        
			        System.out.println("stopped");
					
//			        bufferedOut.flush();
				}
                catch (Exception e) {
                    LOGGER.info("Error while retrieving 7zip entry {}", e);
                    System.out.println("Error while retrieving 7zip entry {}");
				}
                finally {
//                    try { bufferedOut.close(); }
//                    catch(IOException e) {
//                        // Not much we can do about it
//                    	e.printStackTrace();
//                    }

                    try { in.close(); }
                    catch(IOException e) {
                        // Not much we can do about it
                    	e.printStackTrace();
                    }

                    try { sevenZipFile.close(); }
                    catch(IOException e) {
                        // Not much we can do about it
                    	e.printStackTrace();
                    }
                }
//			}
//		});
		
		return new ByteArrayInputStream(os.toByteArray()); */
    final int[] arrays = new int[1];
    for (int i = 0; i < sevenZipFile.size(); i++) {
        // System.out.println("check " + sevenZipFile.getEntry(i).getName());
        if (entry.getPath().equals(sevenZipFile.getEntry(i).getName())) {
            arrays[0] = i;
            break;
        }
    }
    final CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE);
    new Thread(new Runnable() {

        public void run() {
            MuArchiveExtractCallback extractCallbackSpec = new MuArchiveExtractCallback(cbb.getOutputStream(), entry.getPath());
            extractCallbackSpec.Init(sevenZipFile);
            try {
                sevenZipFile.Extract(arrays, 1, IInArchive.NExtract_NAskMode_kExtract, extractCallbackSpec);
            } catch (Exception e) {
                e.printStackTrace();
            // return;
            }
        }
    }).start();
    return cbb.getInputStream();
}
Also used : IInArchive(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive) CircularByteBuffer(com.mucommander.commons.util.CircularByteBuffer) IOException(java.io.IOException) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException)

Example 2 with IInArchive

use of com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive in project mucommander by mucommander.

the class SevenZipArchiveFile method getEntryIterator.

@Override
public ArchiveEntryIterator getEntryIterator() throws IOException {
    final IInArchive sevenZipFile = openSevenZipFile();
    try {
        int nbEntries = sevenZipFile.size();
        Vector<ArchiveEntry> entries = new Vector<ArchiveEntry>();
        for (int i = 0; i < nbEntries; i++) entries.add(createArchiveEntry(sevenZipFile.getEntry(i)));
        return new WrapperArchiveEntryIterator(entries.iterator());
    } finally {
    /*try { sevenZipFile.close(); }
            catch(IOException e) {
                // Not much we can do about it
            }*/
    }
}
Also used : IInArchive(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive) WrapperArchiveEntryIterator(com.mucommander.commons.file.archive.WrapperArchiveEntryIterator) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) Vector(java.util.Vector)

Example 3 with IInArchive

use of com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive in project mucommander by mucommander.

the class J7zip method main.

public static void main(String[] args) throws Exception {
    System.out.println("\nJ7zip 4.43 ALPHA 2 (" + Runtime.getRuntime().availableProcessors() + " CPUs)");
    if (args.length < 2) {
        PrintHelp();
        return;
    }
    final int MODE_LISTING = 0;
    final int MODE_TESTING = 1;
    final int MODE_EXTRACT = 2;
    int mode = -1;
    Vector<String> listOfNames = new Vector<String>();
    for (int i = 2; i < args.length; i++) listOfNames.add(args[i]);
    if (args[0].equals("l")) {
        mode = MODE_LISTING;
    } else if (args[0].equals("t")) {
        mode = MODE_TESTING;
    } else if (args[0].equals("x")) {
        mode = MODE_EXTRACT;
    } else {
        PrintHelp();
        return;
    }
    String filename = args[1];
    MyRandomAccessFile istream = new MyRandomAccessFile(filename, "r");
    IInArchive archive = new Handler();
    int ret = archive.Open(istream);
    if (ret != 0) {
        System.out.println("ERROR !");
        return;
    }
    switch(mode) {
        case MODE_LISTING:
            listing(archive, listOfNames, false);
            break;
        case MODE_TESTING:
            testOrExtract(archive, listOfNames, IInArchive.NExtract_NAskMode_kTest);
            break;
        case MODE_EXTRACT:
            testOrExtract(archive, listOfNames, IInArchive.NExtract_NAskMode_kExtract);
            break;
    }
    archive.close();
}
Also used : IInArchive(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive) Handler(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.SevenZip.Handler) Vector(java.util.Vector)

Aggregations

IInArchive (com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive)3 Vector (java.util.Vector)2 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)1 ArchiveEntry (com.mucommander.commons.file.archive.ArchiveEntry)1 WrapperArchiveEntryIterator (com.mucommander.commons.file.archive.WrapperArchiveEntryIterator)1 Handler (com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.SevenZip.Handler)1 CircularByteBuffer (com.mucommander.commons.util.CircularByteBuffer)1 IOException (java.io.IOException)1