Beispiel #1
0
        public static void Main(String[] args)  //throws Exception
        {
            if (args.Length == 0)
            {
                usage();
                return;
            }
            java.lang.SystemJ.outJ.println("Analysing " + args[0]);
            java.io.File f = new java.io.File(args[0]);
            if (!f.isFile())
            {
                java.lang.SystemJ.err.println(f + " doesn't exist or is a directory");
            }
            java.io.InputStream fis = new java.io.BufferedInputStream(new java.io.FileInputStream(f));
            ArchiveInputStream  ais;

            if (args.Length > 1)
            {
                ais = factory.createArchiveInputStream(args[1], fis);
            }
            else
            {
                ais = factory.createArchiveInputStream(fis);
            }
            java.lang.SystemJ.outJ.println("Created " + ais.toString());
            ArchiveEntry ae;

            while ((ae = ais.getNextEntry()) != null)
            {
                java.lang.SystemJ.outJ.println(ae.getName());
            }
            ais.close();
            fis.close();
        }
Beispiel #2
0
        static java.util.Properties loadFilePrefsImpl(java.io.File file)
        {
            Properties result = new Properties();

            if (!file.exists())
            {
                file.getParentFile().mkdirs();
                return(result);
            }

            if (file.canRead())
            {
                java.io.InputStream        inJ   = null;
                java.nio.channels.FileLock lockJ = null;
                try {
                    java.io.FileInputStream istream = new java.io.FileInputStream(file);
                    inJ = new java.io.BufferedInputStream(istream);
                    java.nio.channels.FileChannel channel = istream.getChannel();
                    lockJ = channel.lockJ(0L, java.lang.Long.MAX_VALUE, true);
                    org.w3c.dom.Document doc     = builder.parse(inJ);
                    org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(doc
                                                                                            .getDocumentElement(), "entry"); //$NON-NLS-1$
                    int length = entries.getLength();
                    for (int i = 0; i < length; i++)
                    {
                        org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item(i);
                        String key   = node.getAttribute("key");                        //$NON-NLS-1$
                        String value = node.getAttribute("value");                      //$NON-NLS-1$
                        result.setProperty(key, value);
                    }
                    return(result);
                } catch (java.io.IOException e) {
                } catch (org.xml.sax.SAXException e) {
                } catch (javax.xml.transform.TransformerException e) {
                    // transform shouldn't fail for xpath call
                    throw new java.lang.AssertionError(e);
                } finally {
                    releaseQuietly(lockJ);
                    closeQuietly(inJ);
                }
            }
            else
            {
                file.delete();
            }
            return(result);
        }
Beispiel #3
0
        public void extractBZip2Test()
        {
            int buffersize = 4096;

            java.io.File bz2 = new java.io.File("C:\\Develop\\Projekte\\J.net\\JavApi Test\\org\\apache\\commons\\compress\\bzip2\\ASL2.bz2");
            java.lang.SystemJ.outJ.println(bz2.toString());
            java.io.FileInputStream     fin  = new java.io.FileInputStream(bz2);
            java.io.BufferedInputStream inJ  = new java.io.BufferedInputStream(fin);
            java.io.FileOutputStream    outJ = new java.io.FileOutputStream("C:\\Develop\\Projekte\\J.net\\JavApi Commons Compress (Apache Port)\\archive.tar");
            org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream bzIn = new org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream(inJ);
            byte[] buffer = new byte[buffersize];
            int    n      = 0;

            while (-1 != (n = bzIn.read(buffer)))
            {
                outJ.write(buffer, 0, n);
            }
            outJ.close();
            bzIn.close();
        }
Beispiel #4
0
        /*
         * Re-initialize the properties and configuration. The initialization
         * process is same as the {@code LogManager} instantiation.
         * <p>
         * Notice : No {@code PropertyChangeEvent} are fired.
         * </p>
         *
         * @throws IOException
         *             if any IO related problems happened.
         * @throws SecurityException
         *             if security manager exists and it determines that caller does
         *             not have the required permissions to perform this action.
         */
        public void readConfiguration()
        {                                                                                             //throws IOException {
            // check config class
            String configClassName = java.lang.SystemJ.getProperty("java.util.logging.config.class"); //$NON-NLS-1$

            if (null == configClassName || null == getInstanceByClass(configClassName))
            {
                // if config class failed, check config file
                String configFile = java.lang.SystemJ.getProperty("java.util.logging.config.file"); //$NON-NLS-1$

                if (null == configFile)
                {
                    // if cannot find configFile, use default logging.properties
                    configFile = new java.lang.StringBuilder().append(
                        java.lang.SystemJ.getProperty("java.home")).append(java.io.File.separator) //$NON-NLS-1$
                                 .append("lib").append(java.io.File.separator).append(             //$NON-NLS-1$
                        "logging.properties").toString();                                          //$NON-NLS-1$
                }

                java.io.InputStream input = null;
                try
                {
                    input = new java.io.BufferedInputStream(new java.io.FileInputStream(configFile));
                    readConfiguration(input);
                }
                finally
                {
                    if (input != null)
                    {
                        try
                        {
                            input.close();
                        }
                        catch (Exception e)
                        {// ignore
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /**
         * Re-initialize the properties and configuration. The initialization
         * process is same as the {@code LogManager} instantiation.
         * <p>
         * Notice : No {@code PropertyChangeEvent} are fired.
         * </p>
         *
         * @throws IOException
         *             if any IO related problems happened.
         * @throws SecurityException
         *             if security manager exists and it determines that caller does
         *             not have the required permissions to perform this action.
         */
        public void readConfiguration()
        {
            //throws IOException {
            // check config class
            String configClassName = java.lang.SystemJ.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
            if (null == configClassName || null == getInstanceByClass(configClassName))
            {
                // if config class failed, check config file
                String configFile = java.lang.SystemJ.getProperty("java.util.logging.config.file"); //$NON-NLS-1$

                if (null == configFile)
                {
                    // if cannot find configFile, use default logging.properties
                    configFile = new java.lang.StringBuilder().append(
                            java.lang.SystemJ.getProperty("java.home")).append(java.io.File.separator) //$NON-NLS-1$
                            .append("lib").append(java.io.File.separator).append( //$NON-NLS-1$
                                    "logging.properties").toString(); //$NON-NLS-1$
                }

                java.io.InputStream input = null;
                try
                {
                    input = new java.io.BufferedInputStream(new java.io.FileInputStream(configFile));
                    readConfiguration(input);
                }
                finally
                {
                    if (input != null)
                    {
                        try
                        {
                            input.close();
                        }
                        catch (Exception e)
                        {// ignore
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /*
         * Find the central directory and read the contents.
         *
         * <p>The central directory can be followed by a variable-length comment
         * field, so we have to scan through it backwards.  The comment is at
         * most 64K, plus we have 18 bytes for the end-of-central-dir stuff
         * itself, plus apparently sometimes people throw random junk on the end
         * just for the fun of it.</p>
         *
         * <p>This is all a little wobbly.  If the wrong value ends up in the EOCD
         * area, we're hosed. This appears to be the way that everybody handles
         * it though, so we're in good company if this fails.</p>
         */
        private void readCentralDir()  //throws IOException {

        /*
         * Scan back, looking for the End Of Central Directory field.  If
         * the archive doesn't have a comment, we'll hit it on the first
         * try.
         *
         * No need to synchronize mRaf here -- we only do this when we
         * first open the Zip file.
         */
        {
            long scanOffset = mRaf.length() - ENDHDR;

            if (scanOffset < 0)
            {
                throw new ZipException("too short to be Zip");
            }

            long stopOffset = scanOffset - 65536;

            if (stopOffset < 0)
            {
                stopOffset = 0;
            }

            while (true)
            {
                mRaf.seek(scanOffset);
                if (ZipEntry.readIntLE(mRaf) == 101010256L)
                {
                    break;
                }

                scanOffset--;
                if (scanOffset < stopOffset)
                {
                    throw new ZipException("EOCD not found; not a Zip archive?");
                }
            }

            /*
             * Found it, read the EOCD.
             *
             * For performance we want to use buffered I/O when reading the
             * file.  We wrap a buffered stream around the random-access file
             * object.  If we just read from the RandomAccessFile we'll be
             * doing a read() system call every time.
             */
            RAFStream rafs = new RAFStream(mRaf, mRaf.getFilePointer());

            java.io.BufferedInputStream bin = new java.io.BufferedInputStream(rafs, ENDHDR);

            int diskNumber         = ler.readShortLE(bin);
            int diskWithCentralDir = ler.readShortLE(bin);
            int numEntries         = ler.readShortLE(bin);
            int totalNumEntries    = ler.readShortLE(bin);

            /*centralDirSize =*/ ler.readIntLE(bin);
            long centralDirOffset = ler.readIntLE(bin);

            /*commentLen =*/ ler.readShortLE(bin);

            if (numEntries != totalNumEntries ||
                diskNumber != 0 ||
                diskWithCentralDir != 0)
            {
                throw new ZipException("spanned archives not supported");
            }

            /*
             * Seek to the first CDE and read all entries.
             * However, when Z_SYNC_FLUSH is used the offset may not point directly
             * to the CDE so skip over until we find it.
             * At most it will be 6 bytes away (one or two bytes for empty block, 4 bytes for
             * empty block signature).
             */
            scanOffset = centralDirOffset;
            stopOffset = scanOffset + 6;

            while (true)
            {
                mRaf.seek(scanOffset);
                if (ZipEntry.readIntLE(mRaf) == CENSIG)
                {
                    break;
                }

                scanOffset++;
                if (scanOffset > stopOffset)
                {
                    throw new ZipException("Central Directory Entry not found");
                }
            }

            // If CDE is found then go and read all the entries
            rafs = new RAFStream(mRaf, scanOffset);
            bin  = new java.io.BufferedInputStream(rafs, 4096);
            for (int i = 0; i < numEntries; i++)
            {
                ZipEntry newEntry = new ZipEntry(ler, bin);
                mEntries.put(newEntry.getName(), newEntry);
            }
        }
Beispiel #7
0
        static java.util.Properties loadFilePrefsImpl(java.io.File file)
        {
            Properties result = new Properties ();
            if (!file.exists ()) {
                file.getParentFile ().mkdirs ();
                return result;
            }

            if (file.canRead ()) {
                java.io.InputStream inJ = null;
                java.nio.channels.FileLock lockJ = null;
                try {
                    java.io.FileInputStream istream = new java.io.FileInputStream (file);
                    inJ = new java.io.BufferedInputStream (istream);
                    java.nio.channels.FileChannel channel = istream.getChannel ();
                    lockJ = channel.lockJ (0L, java.lang.Long.MAX_VALUE, true);
                    org.w3c.dom.Document doc = builder.parse (inJ);
                    org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList (doc
                        .getDocumentElement (), "entry"); //$NON-NLS-1$
                    int length = entries.getLength ();
                    for (int i = 0; i < length; i++) {
                        org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item (i);
                        String key = node.getAttribute ("key"); //$NON-NLS-1$
                        String value = node.getAttribute ("value"); //$NON-NLS-1$
                        result.setProperty (key, value);
                    }
                    return result;
                } catch (java.io.IOException e) {
                } catch (org.xml.sax.SAXException e) {
                } catch (javax.xml.transform.TransformerException e) {
                    // transform shouldn't fail for xpath call
                    throw new java.lang.AssertionError (e);
                } finally {
                    releaseQuietly (lockJ);
                    closeQuietly (inJ);
                }
            } else {
                file.delete ();
            }
            return result;
        }