Package org.apache.commons.compress.archivers.zip

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream$Buffer


    /**
     * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add()}.
     */
    public void testGetWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAdd(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.get());
    }
View Full Code Here


    /**
     * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll()}.
     */
    public void testGetWithAddAll() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAddAll(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.get());
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add()}.
     */
    public void testRemoveWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAdd(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.remove());
    }
View Full Code Here

    /**
     * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()}.
     */
    public void testRemoveWithAddAll() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();

        new DelayedAddAll(blockingBuffer, obj).start();

        // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
        assertSame(obj, blockingBuffer.remove());
    }
View Full Code Here

     * Two read threads should block on an empty buffer until one object
     * is added then both threads should complete.
     */
    public void testBlockedGetWithAdd() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();
       
        // run methods will get and compare -- must wait for add
        Thread thread1 = new ReadThread(blockingBuffer, obj);
        Thread thread2 = new ReadThread(blockingBuffer, obj);
        thread1.start();
        thread2.start();
       
        // give hungry read threads ample time to hang
        delay();
          
        // notifyAll should allow both read threads to complete
        blockingBuffer.add(obj);
       
        // allow notified threads to complete
        delay();
       
        // There should not be any threads waiting.
View Full Code Here

     * Two read threads should block on an empty buffer until a
     * singleton is added then both threads should complete.
     */
    public void testBlockedGetWithAddAll() {

        Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
        Object obj = new Object();
       
        // run methods will get and compare -- must wait for addAll
        Thread thread1 = new ReadThread(blockingBuffer, obj);
        Thread thread2 = new ReadThread(blockingBuffer, obj);
        thread1.start();
        thread2.start();
       
        // give hungry read threads ample time to hang
        delay();
          
        // notifyAll should allow both read threads to complete
        blockingBuffer.addAll(Collections.singleton(obj));
              
        // allow notified threads to complete
        delay();
       
        // There should not be any threads waiting.
View Full Code Here

            newZipStream.closeArchiveEntry();
          } else {
            logger.debug("Adding entries from compressed file...");
            //read the entries from the zip file and copy them to the new zip archive
            //so that we don't have to recompress them.
            ZipArchiveInputStream currentZipStream = new ZipArchiveInputStream(currentFileStream);
            ArchiveEntry currentEntry;
            while ((currentEntry = currentZipStream.getNextEntry()) != null) {
              String entryName = currentEntry.getName();
              logger.debug("Zipping: " + entryName);
              ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName);
              try {
                newZipStream.putArchiveEntry(zipEntry);
              } catch (Exception e){
                //duplicate names should never happen.
                entryName = Math.round(Math.random() * 10000) + "_" + entryName;
                ZipArchiveEntry zipEntry2 = new ZipArchiveEntry(entryName);
                newZipStream.putArchiveEntry(zipEntry2);
              }
              int bytesRead;
              while ((bytesRead = currentZipStream.read(buffer))!= -1) {
                newZipStream.write(buffer, 0, bytesRead);
                    }
              newZipStream.closeArchiveEntry();
            }
            currentZipStream.close();
         
        } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
View Full Code Here

                                                       Path appPath,
                                                       String entry)
      throws IOException {
    InputStream is = null;
    FSDataInputStream appStream = fs.open(appPath);
    ZipArchiveInputStream zis = new ZipArchiveInputStream(appStream);
    ZipArchiveEntry zipEntry;
    boolean done = false;
    while (!done && (zipEntry = zis.getNextZipEntry()) != null) {
      if (entry.equals(zipEntry.getName())) {
        int size = (int) zipEntry.getSize();
        byte[] content = new byte[size];
        int offset = 0;
        while (offset < size) {
          offset += zis.read(content, offset, size - offset);
        }
        is = new ByteArrayInputStream(content);
        done = true;
      }
    }
View Full Code Here

                input = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
            } catch (IOException e) {
                try {
                    input = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
                } catch (IOException e2) {
                    input = new ZipArchiveInputStream(new FileInputStream(file));
                }
            }

            ArchiveEntry entry = input.getNextEntry();
            while (entry != null) {
View Full Code Here

        } else if (a == 0x1f && b == 0x8b) {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-gzip");
            decompress(new GZIPInputStream(stream), xhtml);
        } else if (a == 'P' && b == 'K') {
            metadata.set(Metadata.CONTENT_TYPE, "application/zip");
            unpack(new ZipArchiveInputStream(stream), xhtml);
        } else if ((a == '0' && b == '7')
                || (a == 0x71 && b == 0xc7)
                || (a == 0xc7 && b == 0x71)) {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-cpio");
            unpack(new CpioArchiveInputStream(stream), xhtml);
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream$Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.