Beispiel #1
0
        /**
         * Walks through all recorded entries and adds the data available
         * from the local file header.
         *
         * <p>Also records the offsets for the data to read from the
         * entries.</p>
         */
        private void resolveLocalFileHeaderData(java.util.Map <ZipArchiveEntry, IAC_NameAndComment> entriesWithoutUTF8Flag)
        //throws IOException
        {
            java.util.Enumeration <ZipArchiveEntry> e = getEntries();
            while (e.hasMoreElements())
            {
                ZipArchiveEntry ze          = e.nextElement();
                IAC_OffsetEntry offsetEntry = entries.get(ze);
                long            offset      = offsetEntry.headerOffset;
                archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH);
                byte[] b = new byte[SHORT];
                archive.readFully(b);
                int fileNameLen = ZipShort.getValue(b);
                archive.readFully(b);
                int extraFieldLen = ZipShort.getValue(b);
                int lenToSkip     = fileNameLen;
                while (lenToSkip > 0)
                {
                    int skipped = archive.skipBytes(lenToSkip);
                    if (skipped <= 0)
                    {
                        throw new java.lang.RuntimeException("failed to skip file name in"
                                                             + " local file header");
                    }
                    lenToSkip -= skipped;
                }
                byte[] localExtraData = new byte[extraFieldLen];
                archive.readFully(localExtraData);
                ze.setExtra(localExtraData);

                /*dataOffsets.put(ze,
                 *              new Long(offset + LFH_OFFSET_FOR_FILENAME_LENGTH
                 + SHORT + SHORT + fileNameLen + extraFieldLen));
                 */
                offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH
                                         + SHORT + SHORT + fileNameLen + extraFieldLen;

                if (entriesWithoutUTF8Flag.containsKey(ze))
                {
                    String             orig = ze.getName();
                    IAC_NameAndComment nc   = (IAC_NameAndComment)entriesWithoutUTF8Flag.get(ze);
                    ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name, nc.comment);
                    if (!orig.equals(ze.getName()))
                    {
                        nameMap.remove(orig);
                        nameMap.put(ze.getName(), ze);
                    }
                }
            }
        }
Beispiel #2
0
        /**
         * Reading a column definition from file<br>
         * @param ff file handle (correctly positioned)
         * @param iCol index starts with 1
         * @param locn offset to the current column
         * @return struct with column info
         */
        internal static TsColumn readColdef(java.io.RandomAccessFile ff, String tableName, int iCol, int locn) //throws tinySQLException
        {
            try
            {
                // seek the position of the field definition data.
                // This information appears after the first 32 byte
                // table information, and lives in 32 byte chunks.
                //
                ff.seek((iCol - 1) * 32 + 32);

                // get the column name into a byte array
                //
                byte[] b = new byte[11];
                ff.readFully(b);

                // convert the byte array to a String
                // Seek first 0x00 occurence and strip array after that
                //
                // some C-implementations do not set the remaining bytes
                // after the name to 0x00, so we have to correct this.
                //bool clear = false;
                int i = 0;
                while ((i < 11) && (b[i] != 0))
                {
                    i++;
                }
                while (i < 11)
                {
                    b[i] = 0;
                    i++;
                }
                String colName = (new java.lang.StringJ(b, Utils.encode)).trim();
                // read in the column type which follows the 11 byte column name
                //
                byte[] c = new byte[1];
                c[0] = ff.readByte();
                String ftyp = new java.lang.StringJ(c, Utils.encode);

                // skip four bytes
                //
                ff.skipBytes(4);

                // get field length and precision which are in the two bytes following
                // the column type.
                //
                short flen = Utils.fixByte(ff.readByte()); // 16
                short fdec = Utils.fixByte(ff.readByte()); // 17
                if (ftyp.equals("N") & fdec == 0)
                {
                    ftyp = "I";
                }

                // bytes 18 - 31 are reserved

                // create a new tsColumn object and assign it the
                // attributes of the current field
                //
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Try and create tsColumn for " + colName);
                }
                TsColumn column = new TsColumn(colName);

                /*
                 *    The column type is now given as java.sql.Types constant
                 */
                column.type          = typeToSQLType(ftyp);
                column.size          = flen;
                column.decimalPlaces = fdec;
                column.position      = locn + 1; // set the field position to the current
                column.tableName     = tableName;
                return(column);
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }