Esempio n. 1
0
        //throws IOException {

        /**
         * Opens the given file for reading, assuming the specified
         * encoding for file names.
         *
         * @param f the archive.
         * @param encoding the encoding to use for file names, use null
         * for the platform's default encoding
         * @param useUnicodeExtraFields whether to use InfoZIP Unicode
         * Extra Fields (if present) to set the file names.
         *
         * @throws IOException if an error occurs while reading the file.
         */
        public ZipFile(java.io.File f, String encoding, bool useUnicodeExtraFields)
        //throws IOException
        {
            this.OFFSET_COMPARATOR     = new IAC_OFFSET_COMPARATOR(this);
            this.encoding              = encoding;
            this.zipEncoding           = ZipEncodingHelper.getZipEncoding(encoding);
            this.useUnicodeExtraFields = useUnicodeExtraFields;
            archive = new java.io.RandomAccessFile(f, "r");
            bool success = false;

            try {
                java.util.Map <ZipArchiveEntry, IAC_NameAndComment> entriesWithoutUTF8Flag = populateFromCentralDirectory();
                resolveLocalFileHeaderData(entriesWithoutUTF8Flag);
                success = true;
            } finally {
                if (!success)
                {
                    try {
                        archive.close();
                    } catch (java.io.IOException) {
                        // swallow, throw the original exception instead
                    }
                }
            }
        }
Esempio n. 2
0
        /*
         * Closes this ZIP file. This method is idempotent.
         *
         * @throws IOException
         *             if an IOException occurs.
         */
        public void close() // throws IOException {
        {
            java.io.RandomAccessFile raf = mRaf;

            if (raf != null)   // Only close initialized instances
            {
                lock (raf) {
                    mRaf = null;
                    raf.close();
                }
                if (fileToDeleteOnClose != null)
                {
                    new java.io.File(fileName).delete();

                    /*AccessController.doPrivileged(new PrivilegedAction<Object>() {
                     *  public Object run() {
                     *      new File(fileName).delete();
                     *      return null;
                     *  }
                     * });*/
                    // fileToDeleteOnClose.delete();
                    fileToDeleteOnClose = null;
                }
            }
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        protected void initOverFile(java.io.File file, String fileName)
        {
            this.file = file;

            this.linkName = "";

            if (file.isDirectory())
            {
                this.mode     = DEFAULT_DIR_MODE;
                this.linkFlag = TarConstants.LF_DIR;

                int nameLength = fileName.length();
                if (nameLength == 0 || fileName.charAt(nameLength - 1) != '/')
                {
                    this.name = fileName + "/";
                }
                else
                {
                    this.name = fileName;
                }
                this.size = 0;
            }
            else
            {
                this.mode     = DEFAULT_FILE_MODE;
                this.linkFlag = TarConstants.LF_NORMAL;
                this.size     = file.length();
                this.name     = fileName;
            }

            this.modTime  = file.lastModified() / MILLIS_PER_SECOND;
            this.devMajor = 0;
            this.devMinor = 0;
        }
Esempio n. 5
0
        /*
         * Scan the given directory for files containing the substrMatch<br>
         * Small case extensions '.dbf' are recognized and returned as '.DBF'
         */
        public static java.util.Vector <Object> getAllFiles(String path, String suffix)
        {
            java.util.Vector <Object> vec = null;
            String[]     fileNameList;
            java.io.File currentDir, f;
            String       fileName, upperSuffix;
            int          i;

            upperSuffix  = suffix.toUpperCase();
            currentDir   = new java.io.File(path);
            fileNameList = currentDir.list();
            if (fileNameList == null)
            {
                java.lang.SystemJ.outJ.println("*** null for " + path);
            }
            else
            {
                vec = new java.util.Vector <Object>(fileNameList.Length);
                for (i = 0; i < fileNameList.Length; i++)
                {
                    f = new java.io.File(fileNameList[i]);
                    if (!f.isDirectory())
                    {
                        fileName = f.getPath().toString().toUpperCase();
                        //           lastModified = new java.util.Date(f.lastModified());
                        if (upperSuffix == null | fileName.endsWith(upperSuffix))
                        {
                            vec.addElement(f);
                        }
                    }
                }
            }
            return(vec);
        }
Esempio n. 6
0
        public void Test_FileHidden()
        {
            switch (System.Environment.OSVersion.Platform)
            {
            case PlatformID.Unix:
            case PlatformID.MacOSX:
                String name = java.lang.SystemJ.getProperty("java.io.tmpdir") + ".VampireApi.secret";

                java.io.File hidden = new java.io.File(name);
                if (!hidden.exists())
                {
                    String content = "secret=geheimnis";
                    byte[]  value  = System.Text.Encoding.GetEncoding("utf-8").GetBytes(content);

                    java.io.FileOutputStream fos = new java.io.FileOutputStream(name);
                    fos.write(value, 0, value.Length);
                    fos.flush();
                    fos.close();
                }
                Assert.True(new java.io.File(name).exists(), "java.io.File.exists() found not file " + name);
                Assert.True(hidden.isHidden(), "File " + hidden.toString() + " should be hidden");
                break;

            default:
                Assert.Warn("Test_FileHidden not implemented for this platform");
                break;
            }
        }
Esempio n. 7
0
 static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs)
 {        //throws IOException {
     java.io.BufferedWriter     outJ  = null;
     java.nio.channels.FileLock lockJ = null;
     try {
         java.io.FileOutputStream ostream = new java.io.FileOutputStream(file);
         outJ = new java.io.BufferedWriter(new java.io.OutputStreamWriter(ostream, "UTF-8"));                   //$NON-NLS-1$
         java.nio.channels.FileChannel channel = ostream.getChannel();
         lockJ = channel.lockJ();
         outJ.write(HEADER);
         outJ.newLine();
         outJ.write(FILE_PREFS);
         outJ.newLine();
         if (prefs.size() == 0)
         {
             exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, outJ);
         }
         else
         {
             String[] keys = prefs.keySet()
                             .toArray(new String[prefs.size()]);
             int      length = keys.Length;
             String[] values = new String[length];
             for (int i = 0; i < length; i++)
             {
                 values [i] = prefs.getProperty(keys [i]);
             }
             exportEntries(keys, values, outJ);
         }
         outJ.flush();
     } finally {
         releaseQuietly(lockJ);
         closeQuietly(outJ);
     }
 }
Esempio n. 8
0
        /*
         * Opens a file as <i>ZIP-archive</i>. "mode" must be {@code OPEN_READ} or
         * {@code OPEN_DELETE} . The latter sets the "delete on exit" flag through a
         * file.
         *
         * @param file
         *            the ZIP file to read.
         * @param mode
         *            the mode of the file open operation.
         * @throws IOException
         *             if an {@code IOException} occurs.
         */
        public ZipFile(java.io.File file, int mode)  //throws IOException {
        {
            fileName = file.getPath();
            if (mode != OPEN_READ && mode != (OPEN_READ | OPEN_DELETE))
            {
                throw new java.lang.IllegalArgumentException();
            }

/*            java.lang.SecurityManager security = java.lang.SystemJ.getSecurityManager();
 *          if (security != null) {
 *              security.checkRead(fileName);
 *          }*/
            if ((mode & OPEN_DELETE) != 0)
            {
/*                if (security != null) {
 *                  security.checkDelete(fileName);
 *              }*/
                fileToDeleteOnClose = file; // file.deleteOnExit();
            }
            else
            {
                fileToDeleteOnClose = null;
            }

            mRaf = new java.io.RandomAccessFile(fileName, "r");

            readCentralDir();
        }
Esempio n. 9
0
        /**
         * rename a file
         * @return true if succeeded
         */
        public static bool renameFile(String oldName, String newName)
        {
            java.io.File f_old = new java.io.File(oldName);
            java.io.File f_new = new java.io.File(newName);
            bool         ret   = f_old.renameTo(f_new);

            return(ret);
        }
Esempio n. 10
0
        /*
         * Make the data directory unless it already exists
         */
        void mkDataDirectory(String dataDir) //throws NullPointerException
        {
            java.io.File dd = new java.io.File(dataDir);

            if (!dd.exists())
            {
                dd.mkdir();
            }
        }
Esempio n. 11
0
 /**
  * Create a new {@code JarFile} using the contents of file.
  *
  * @param file
  *            the JAR file as {@link File}.
  * @param verify
  *            if this JAR filed is signed whether it must be verified.
  * @param mode
  *            the mode to use, either {@link ZipFile#OPEN_READ OPEN_READ} or
  *            {@link ZipFile#OPEN_DELETE OPEN_DELETE}.
  * @throws IOException
  *             If the file cannot be read.
  */
 public JarFile(java.io.File file, bool verify, int mode) ://throws IOException {
     base(file, mode)
 {
     if (verify)
     {
         verifier = new JarVerifier(file.getPath());
     }
     readMetaEntries();
 }
Esempio n. 12
0
 /**
  * Creates a new zip entry taking some information from the given
  * file and using the provided name.
  *
  * <p>The name will be adjusted to end with a forward slash "/" if
  * the file is a directory.  If the file is not a directory a
  * potential trailing forward slash will be stripped from the
  * entry name.</p>
  *
  * <p>Must not be used if the stream has already been closed.</p>
  */
 public override ArchiveEntry createArchiveEntry(java.io.File inputFile, String entryName)
 //throws IOException
 {
     if (finished)
     {
         throw new java.io.IOException("Stream has already been finished");
     }
     return(new ZipArchiveEntry(inputFile, entryName));
 }
Esempio n. 13
0
        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args)
        {
            java.io.File dir = new java.io.File(args[0]);

            start_base = java.lang.SystemJ.currentTimeMillis();

            scanFiles(dir.listFiles());
            print("DONE ================================== ", 45, false);
            print(getTime(java.lang.SystemJ.currentTimeMillis() - start_base), 10, true);
        }
Esempio n. 14
0
 /**
  * Create a new instance using the attributes of the given file
  */
 public ArArchiveEntry(java.io.File inputFile, String entryName)
 {
     // TODO sort out mode
     this.name         = entryName;
     this.length       = inputFile.isFile() ? inputFile.length() : 0;
     this.userId       = 0;
     this.groupId      = 0;
     this.mode         = DEFAULT_MODE;
     this.lastModified = inputFile.lastModified() / 1000;
 }
Esempio n. 15
0
 /**
  * Creates a new zip entry taking some information from the given
  * file and using the provided name.
  *
  * <p />The name will be adjusted to end with a forward slash "/" if
  * the file is a directory.  If the file is not a directory a
  * potential trailing forward slash will be stripped from the
  * entry name.
  */
 public ZipArchiveEntry(java.io.File inputFile, String entryName)
     : base(inputFile.isDirectory() && !entryName.EndsWith("/") ?  entryName + "/" : entryName)
 {
     setName(inputFile.isDirectory() && !entryName.EndsWith("/") ?  entryName + "/" : entryName);
     if (inputFile.isFile())
     {
         setSize(inputFile.length());
     }
     setTime(inputFile.lastModified());
     // TODO are there any other fields we can set here?
 }
Esempio n. 16
0
        public void Test_FileParentFile()
        {
            String expected = System.Reflection.Assembly.GetAssembly(typeof(java.lang.SystemJ)).Location;

            expected = expected.Substring(0, expected.Length - "/VampireApi.dll".Length);

            java.io.File runtimeDll = new java.io.File(System.Reflection.Assembly.GetAssembly(typeof(java.lang.SystemJ)).Location);
            String       actually   = runtimeDll.getParentFile().toString();

            Assert.AreEqual(expected, actually);
        }
Esempio n. 17
0
 /**
  * Set the file this RPMFile should represent
  *
  * @param fh The file object representing a rpm file
  */
 public void setFile(java.io.File fh)
 {
     lock (this)
     {
         if (editingRpmFile)
         {
             throw new java.lang.IllegalStateException("RPM file is currently edited");
         }
         rpmFile = fh;
         reset();
     }
 }
Esempio n. 18
0
        /**
         * Flushes and closes all opened files.
         *
         * @throws SecurityException
         *             if a security manager exists and it determines that the
         *             caller does not have the required permissions to control this
         *             handler; required permissions include
         *             {@code LogPermission("control")},
         *             {@code FilePermission("write")} etc.
         */

        public override void close()
        {
            // release locks
            base.close();
            allLocks.remove(fileName);
            try {
                java.nio.channels.FileChannel channel = lockJ.channel();
                lockJ.release();
                channel.close();
                java.io.File file = new java.io.File(fileName + LCK_EXT);
                file.delete();
            } catch (java.io.IOException e) {
                // ignore
            }
        }
Esempio n. 19
0
        /*
         * Delete a file in the data directory
         */
        public static void delFile(String fname) //throws NullPointerException, IOException
        {
            java.io.File f = new java.io.File(fname);

            // only delete a file that exists
            //
            if (f.exists())
            {
                // try the delete. If it fails, complain
                //
                if (!f.delete())
                {
                    throw new java.io.IOException("Could not delete: " + f.getAbsolutePath() + ".");
                }
            }
        }
Esempio n. 20
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);
        }
Esempio n. 21
0
        public static void delFile(String dataDir, String fname)
        {//throws NullPointerException, IOException {
            java.io.File f = new java.io.File(dataDir + java.io.File.separator + fname);

            // only delete a file that exists
            //
            if (f.exists())
            {
                // try the delete. If it fails, complain
                //
                if (!f.delete())
                {
                    throw new java.io.IOException("Could not delete file: " +
                                                  dataDir + "/" + fname + ".");
                }
            }
        }
Esempio n. 22
0
        /*
         * Parse the content of the given file as an XML document
         * and return a new DOM {@link Document} object.
         * An <code>IllegalArgumentException</code> is thrown if the
         * <code>File</code> is <code>null</code> null.
         *
         * @param f The file containing the XML to parse.
         * @exception IOException If any IO errors occur.
         * @exception SAXException If any parse errors occur.
         * @see org.xml.sax.DocumentHandler
         * @return A new DOM Document object.
         */

        public Document parse(java.io.File f)
        {        // throws SAXException, IOException {
            if (f == null)
            {
                throw new java.lang.IllegalArgumentException("File cannot be null");
            }

            String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath());

            if (DEBUG)
            {
                java.lang.SystemJ.outJ.println("Escaped URI = " + escapedURI);
            }

            InputSource inJ = new InputSource(escapedURI);

            return(parse(inJ));
        }
Esempio n. 23
0
 public void readFile()
 {
     // Step 1 - file greater than FileBuffer
     java.io.File           file = new java.io.File("/Develop/Projekte/Kobol/ITIL RPC/src/biz/ritter/dbms/views/AufgabenUebersichtView.java");
     java.io.BufferedReader br   = new java.io.BufferedReader(new java.io.FileReader(file));
     while (br.ready())
     {
         char c = (char)br.read();
         java.lang.SystemJ.outJ.print(c);
     }
     // Step 2 - file smaller than FileBuffer
     file = new java.io.File("/Develop/Projekte/Kobol/ITIL RPC/src/biz/ritter/dbms/ItilActivator.java");
     br   = new java.io.BufferedReader(new java.io.FileReader(file));
     while (br.ready())
     {
         char c = (char)br.read();
         java.lang.SystemJ.outJ.print(c);
     }
 }
Esempio n. 24
0
        public Process exec(String[] cmdArray, String[] env, java.io.File dir)
        {
            Process p = new Process();

            p.StartInfo.WorkingDirectory = (null != dir) ? dir.toString() : SystemJ.getProperty("user.dir");
            p.StartInfo.FileName         = cmdArray[0];
            for (int i = 0; i < env.Length; i++)
            {
                String [] keyValue = env [i].Split('=');
                p.StartInfo.EnvironmentVariables.Add(keyValue[0], keyValue[1]);
            }
            for (int i = 1; i < cmdArray.Length; i++)
            {
                p.StartInfo.Arguments.Insert(i - 1, cmdArray[i]);
            }
            p.StartInfo.UseShellExecute = true;
            p.Start();
            return(p);
        }
Esempio n. 25
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();
        }
Esempio n. 26
0
        protected void init(String name, bool preserveLeadingSlashes)
        {
            this.magic    = TarConstants.MAGIC_POSIX;
            this.version  = TarConstants.VERSION_POSIX;
            this.name     = "";
            this.linkName = "";

            String user = java.lang.SystemJ.getProperty("user.name", "");

            if (user.length() > MAX_NAMELEN)
            {
                user = user.Substring(0, MAX_NAMELEN);
            }

            this.userId    = 0;
            this.groupId   = 0;
            this.userName  = user;
            this.groupName = "";
            this.file      = null;
        }
Esempio n. 27
0
        private static java.sql.Connection dbConnect(String tinySQLDir)// throws SQLException
        {
            java.sql.Connection       con = null;
            java.sql.DatabaseMetaData dbMeta;
            java.io.File   conPath;
            java.io.File[] fileList;
            String         tableName;

            java.sql.ResultSet tables_rs;
            conPath  = new java.io.File(tinySQLDir);
            fileList = conPath.listFiles();
            if (fileList == null)
            {
                java.lang.SystemJ.outJ.println(tinySQLDir + " is not a valid directory.");
                return((java.sql.Connection)null);
            }
            else
            {
                java.lang.SystemJ.outJ.println("Connecting to " + conPath.getAbsolutePath());
                con = java.sql.DriverManager.getConnection("jdbc:dbfFile:" + conPath, "", "");
            }
            dbMeta    = con.getMetaData();
            tables_rs = dbMeta.getTables(null, null, null, null);
            tableList = new java.util.Vector <Object>();
            while (tables_rs.next())
            {
                tableName = tables_rs.getString("TABLE_NAME");
                tableList.addElement(tableName);
            }
            if (tableList.size() == 0)
            {
                java.lang.SystemJ.outJ.println("There are no tinySQL tables in this directory.");
            }
            else
            {
                java.lang.SystemJ.outJ.println("There are " + tableList.size() + " tinySQL tables"
                                               + " in this directory.");
            }
            return(con);
        }
Esempio n. 28
0
        public static void readLongNames(String inputDataDir)
        {
            String fullPath, longNameRecord;

            String[]       fields;
            FieldTokenizer ft;

            java.io.File longColumnNameFile;
            dataDir = inputDataDir;
            java.io.BufferedReader longNameReader = (java.io.BufferedReader)null;
            fullPath           = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
            longColumnNames    = new java.util.Vector <Object>();
            longColumnNameFile = new java.io.File(fullPath);
            if (longColumnNameFile.exists())
            {
                try
                {
                    longNameReader = new java.io.BufferedReader(new java.io.FileReader(fullPath));
                    while ((longNameRecord = longNameReader.readLine()) != null)
                    {
                        ft     = new FieldTokenizer(longNameRecord, '|', false);
                        fields = ft.getFields();
                        longColumnNames.addElement(fields[0]);
                        longColumnNames.addElement(fields[1]);
                    }
                    longNameReader.close();
                    longNamesInFileCount = longColumnNames.size() / 2;
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Long Names read: " + longNamesInFileCount);
                    }
                }
                catch (Exception readEx)
                {
                    java.lang.SystemJ.outJ.println("Reader exception " + readEx.getMessage());
                    longNamesInFileCount = 0;
                }
            }
        }
Esempio n. 29
0
 /**
  * Creates a new ZIP OutputStream writing to a File.  Will use
  * random access if possible.
  * @param file the file to zip to
  * @throws IOException on error
  */
 public ZipArchiveOutputStream(java.io.File file) //throws IOException
 {
     java.io.OutputStream     o    = null;
     java.io.RandomAccessFile _raf = null;
     try {
         _raf = new java.io.RandomAccessFile(file, "rw");
         _raf.setLength(0);
     } catch (java.io.IOException) {
         if (_raf != null)
         {
             try {
                 _raf.close();
             } catch (java.io.IOException) {
                 // ignore
             }
             _raf = null;
         }
         o = new java.io.FileOutputStream(file);
     }
     outJ = o;
     raf  = _raf;
 }
Esempio n. 30
0
        /**
         * Creates a CPIOArchiveEntry with a specified name for a
         * specified file.
         *
         * @param format
         *            The cpio format for this entry.
         * @param inputFile
         *            The file to gather information from.
         * @param entryName
         *            The name of this entry.
         * <br/>
         * Possible format values are:
         * <p>
         * CpioConstants.FORMAT_NEW<br/>
         * CpioConstants.FORMAT_NEW_CRC<br/>
         * CpioConstants.FORMAT_OLD_BINARY<br/>
         * CpioConstants.FORMAT_OLD_ASCII<br/>
         *
         * @since Apache Commons Compress 1.1
         */
        public CpioArchiveEntry(short format, java.io.File inputFile, String entryName)
        {
            this.setFileFormat(format);
            this.name = entryName;
            this.setSize(inputFile.isFile() ? inputFile.length() : 0);
            long mode = 0;

            if (inputFile.isDirectory())
            {
                mode |= CpioConstants.C_ISDIR;
            }
            else if (inputFile.isFile())
            {
                mode |= CpioConstants.C_ISREG;
            }
            else
            {
                throw new java.lang.IllegalArgumentException("Cannot determine type of file "
                                                             + inputFile.getName());
            }
            // TODO set other fields as needed
            setMode(mode);
            setTime(inputFile.lastModified() / 1000);
        }
Esempio n. 31
0
        // throws ConfigurationError
        /**
         * Finds the implementation Class object in the specified order.  Main
         * entry point.
         * @return Class object of factory, never null
         *
         * @param factoryId             Name of the factory to find, same as
         *                              a property name
         * @param fallbackClassName     Implementation class name, if nothing else
         *                              is found.  Use null to mean no fallback.
         *
         * Package private so this code can be shared.
         */
        internal static Object find(String factoryId, String fallbackClassName)
        {
            // Figure out which ClassLoader to use for loading the provider
            // class.  If there is a Context ClassLoader then use it.

            java.lang.ClassLoader classLoader = SecuritySupport.getContextClassLoader ();

            if (classLoader == null) {
                // if we have no Context ClassLoader
                // so use the current ClassLoader
                classLoader = typeof(FactoryFinder).getClass ().getClassLoader ();
            }

            if (debug)
                dPrint ("find factoryId =" + factoryId);

            // Use the system property first
            try {
                String systemProp = SecuritySupport.getSystemProperty (factoryId);
                if (systemProp != null && systemProp.length () > 0) {
                    if (debug)
                        dPrint ("found system property, value=" + systemProp);
                    return newInstance (systemProp, classLoader, true);
                }
            } catch (java.lang.SecurityException se) {
                //if first option fails due to any reason we should try next option in the
                //look up algorithm.
            }

            // try to read from $java.home/lib/jaxp.properties
            try {
                String javah = SecuritySupport.getSystemProperty ("java.home");
                String configFile = javah + java.io.File.separator +
                                            "lib" + java.io.File.separator + "jaxp.properties";
                String factoryClassName = null;
                if (firstTime) {
                    lock (cacheProps) {
                        if (firstTime) {
                            java.io.File f = new java.io.File (configFile);
                            firstTime = false;
                            if (SecuritySupport.doesFileExist (f)) {
                                if (debug)
                                    dPrint ("Read properties file " + f);
                                //cacheProps.load( new FileInputStream(f));
                                cacheProps.load (SecuritySupport.getFileInputStream (f));
                            }
                        }
                    }
                }
                factoryClassName = cacheProps.getProperty (factoryId);

                if (factoryClassName != null) {
                    if (debug)
                        dPrint ("found in $java.home/jaxp.properties, value=" + factoryClassName);
                    return newInstance (factoryClassName, classLoader, true);
                }
            } catch (java.lang.Exception ex) {
                if (debug)
                    ex.printStackTrace ();
            }

            // Try Jar Service Provider Mechanism
            Object provider = findJarServiceProvider (factoryId);
            if (provider != null) {
                return provider;
            }
            if (fallbackClassName == null) {
                throw new ConfigurationError (
                    "Provider for " + factoryId + " cannot be found", null);
            }

            if (debug)
                dPrint ("loaded from fallback value: " + fallbackClassName);
            return newInstance (fallbackClassName, classLoader, true);
        }
Esempio n. 32
0
 /**
  * Changes the working directory of this process builder. If the specified
  * directory is {@code null}, then the working directory of the Java
  * process is used when a process is started.
  *
  * @param directory
  *            the new working directory for this process builder.
  * @return this process builder instance.
  */
 public ProcessBuilder directory(java.io.File directoryJ)
 {
     this.directoryJ = directoryJ;
     return this;
 }
Esempio n. 33
0
 private void initOutputFiles()
 {
     //throws FileNotFoundException, IOException {
     while (true) {
     // try to find a unique file which is not locked by other process
     uniqueID++;
     // FIXME: improve performance here
     for (int generation = 0; generation < count; generation++) {
         // cache all file names for rotation use
         files[generation] = new java.io.File(parseFileName(generation));
     }
     fileName = files[0].getAbsolutePath();
     lock (allLocks) {
         /*
          * if current process has held lock for this fileName continue
          * to find next file
          */
         if (null != allLocks.get(fileName)) {
             continue;
         }
         if (files[0].exists()
                 && (!append || files[0].length() >= limit)) {
             for (int i = count - 1; i > 0; i--) {
                 if (files[i].exists()) {
                     files[i].delete();
                 }
                 files[i - 1].renameTo(files[i]);
             }
         }
         java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName
                 + LCK_EXT);
         java.nio.channels.FileChannel channel = fileStream.getChannel();
         /*
          * if lock is unsupported and IOException thrown, just let the
          * IOException throws out and exit otherwise it will go into an
          * undead cycle
          */
         lockJ = channel.tryLock();
         if (null == lockJ) {
             try {
                 fileStream.close();
             } catch (Exception e) {
                 // ignore
             }
             continue;
         }
         allLocks.put(fileName, lockJ);
         break;
     }
     }
     output = new MeasureOutputStream(new java.io.BufferedOutputStream(
         new java.io.FileOutputStream(fileName, append)), files[0].length());
     setOutputStream(output);
 }
Esempio n. 34
0
 /**
  * Flushes and closes all opened files.
  *
  * @throws SecurityException
  *             if a security manager exists and it determines that the
  *             caller does not have the required permissions to control this
  *             handler; required permissions include
  *             {@code LogPermission("control")},
  *             {@code FilePermission("write")} etc.
  */
 public override void close()
 {
     // release locks
     base.close();
     allLocks.remove(fileName);
     try {
     java.nio.channels.FileChannel channel = lockJ.channel();
     lockJ.release();
     channel.close();
     java.io.File file = new java.io.File(fileName + LCK_EXT);
     file.delete();
     } catch (java.io.IOException e) {
     // ignore
     }
 }
Esempio n. 35
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;
            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home") //$NON-NLS-1$
                    + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                    + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException e)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops = new java.util.Properties();
                        loaded = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException e)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException e)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }