Beispiel #1
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() + ".");
                }
            }
        }
Beispiel #2
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));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        /*
         * opens a DBF file. This is based on Pratap Pereira's
         * Xbase.pm perl module
         * @return column definition list (java.util.Hashtable<Object,Object>)
         *
         * @author Thomas Morgner <*****@*****.**> added check for
         * file exists, before the file is opened. Opening a non existing
         * file will create a new file, and we get errors while trying
         * to read the non-existend headers
         */
        java.util.Hashtable <Object, Object> open_dbf() //throws TinySQLException
        {
            try
            {
                java.io.File f = new java.io.File(fullPath);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Try to open  " + f.getAbsolutePath());
                }
                if (!f.exists())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - does not exist. or can't be read.");
                }
                else if (!f.canRead())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - file can't be read (permissions?).");
                }
                if (f.canWrite())
                {
                    ftbl = new java.io.RandomAccessFile(f, "rw");
                }
                else
                {
                    /*
                     *          Open readonly if the file is not writeable. Needed for
                     *          databases on CD-Rom
                     */
                    ftbl = new java.io.RandomAccessFile(f, "r");
                }

                /*
                 *       Read the first 32 bytes ...
                 */
                dbfHeader = new DBFHeader(ftbl);

                /*
                 *       read the column info (each is a 32 byte bulk) ...
                 */
                java.util.Hashtable <Object, Object> coldef_list = new java.util.Hashtable <Object, Object>();
                columnNameKeys = new java.util.Vector <Object>();
                int locn = 0; // offset of the current column
                for (int i = 1; i <= dbfHeader.numFields; i++)
                {
                    TsColumn coldef = DBFFile.readColdef(ftbl, table, i, locn);
                    locn += coldef.size; // increment locn by the length of this field.
                    coldef_list.put(coldef.name, coldef);
                    columnNameKeys.addElement(coldef.name);
                }
                fileOpen = true;
                return(coldef_list);
            }
            catch (Exception e)
            {
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.err.println(e.ToString());                      // e.printStackTrace();
                }
                throw new TinySQLException(e.getMessage());
            }
        }