/** * @param tag * @param i * @param b */ private static void print(DataTypeIf tag, int size, bool right) { String str = ""; if (tag != null) { str = tag.toString(); } print(str, size, right); }
/** * This method creates a rpm data type out of a input stream and an * IndexEntry. The object must at the current position of the input stream. * The length is only needed for string objects; the string objects will * read length bytes of the input stream and will try to convert the data * into a rpm data type. * * @param inputStream * The input stream * @param indexEntry * The IndexEntry that should be read * @param length * The number of bytes to read for string objects * * @return One of the rpm data types coresponding with the type contained in * the IndexEntry. * * @throws IOException * if something was wrong during reading of the input stream */ public static DataTypeIf createFromStream( java.io.DataInputStream inputStream, IndexEntry indexEntry, long length) {//throws IOException { DataTypeIf ret = null; switch ((int)indexEntry.getType().getId()) { case RPMIndexType._NULL: ret = NULL.readFromStream(indexEntry); break; case RPMIndexType._CHAR: ret = CHAR.readFromStream(inputStream, indexEntry); break; case RPMIndexType._INT8: ret = INT8.readFromStream(inputStream, indexEntry); break; case RPMIndexType._INT16: ret = INT16.readFromStream(inputStream, indexEntry); break; case RPMIndexType._INT32: ret = INT32.readFromStream(inputStream, indexEntry); break; case RPMIndexType._INT64: ret = INT64.readFromStream(inputStream, indexEntry); break; case RPMIndexType._STRING: ret = STRING.readFromStream(inputStream, indexEntry, length); break; case RPMIndexType._BIN: ret = BIN.readFromStream(inputStream, indexEntry); break; case RPMIndexType._STRING_ARRAY: ret = STRING_ARRAY.readFromStream(inputStream, indexEntry, length); break; case RPMIndexType._I18NSTRING: ret = I18NSTRING.readFromStream(inputStream, indexEntry, length); break; default: // TODO: UNKNOWN break; } return(ret); }
/** * Get a tag by id as a Long * * @param tag A tag id as a Long * @return A data struct containing the data of this tag */ public DataTypeIf getTag(java.lang.Long tag) { lock (this) { DataTypeIf data = store.getTag(tag); // set the locale for all I18N strings if (data is I18NSTRING) { ((I18NSTRING)data).setLocaleIndex(localePosition); } return(data); } }
/** * Create a header structure from an input stream. <p/> The header * structure of a signature or a header can be read and also the index * entries containing the tags for this rpm section (signature or * header). <p/> Unless we have a raw header from headerUnload or the * database, a header is read consisting of the following fields: * <code><pre> * byte magic[3]; (3 byte) (8e ad e8) * int version; (1 byte) * byte reserved[4]; (4 byte) * long num_index; (4 byte) * long num_data; (4 byte) * </pre></code> <p/> Afterwards the index entries are read and then the tags * and the correspondig data entries are read. * * @param inputStream * An inputstream containing rpm file informations * @param rawHeader * Are we a raw header (from headerUnload or rpmdb) * @throws IOException * if an error occurs on reading informations out of the * stream */ public Header(java.io.DataInputStream inputStream, bool rawHeader, Store store) {//throws IOException { this.store = store; if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Start Reading Header"); } if (!rawHeader) { // Read header size = HEADER_LENGTH; int magic = 0; do { magic = inputStream.readUnsignedByte(); if (magic == 0) { inputStream.skip(7); } } while (magic == 0); check(magic == 0x8E, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0x8E"); magic = inputStream.readUnsignedByte(); check(magic == 0xAD, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xAD"); magic = inputStream.readUnsignedByte(); check(magic == 0xE8, "Header magic 0x" + java.lang.Integer.toHexString(magic) + " != 0xE8"); version = inputStream.readUnsignedByte(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("version: " + version); } // skip reserved bytes inputStream.skipBytes(4); } indexNumber = inputStream.readInt(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("indexes available: " + indexNumber); } indexDataSize = inputStream.readInt(); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("index data size: " + indexDataSize); } // Read indexes // make sure to sort them in order of offset to // be able to read the store without jumping arround in // the file java.util.TreeSet <IndexEntry> _indexes = new java.util.TreeSet <IndexEntry>(new IAC_IndexesComparator()); for (int i = 0; i < this.indexNumber; i++) { IndexEntry index = new IndexEntry(inputStream); _indexes.add(index); size += index.getSize(); } indexes = new IndexEntry[0]; indexes = (IndexEntry[])_indexes.toArray(indexes); // Read store for (int i = 0; i < indexes.Length; i++) { IndexEntry index = indexes[i]; // if (index.getType().equals(RPMIndexType.STRING_ARRAY) || // index.getType().equals(RPMIndexType.STRING) || // index.getType().equals(RPMIndexType.I18NSTRING)) { // if (i < (indexes.length - 1)) { // IndexEntry next = indexes[i + 1]; // // length = next.getOffset() - index.getOffset(); // } else { // length = indexDataSize - index.getOffset(); // } // // // and initialize temporary space for data // stringData = new byte[(int) length]; // // // and read it from stream // inputStream.readFully(stringData); // } DataTypeIf dataObject = null; if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Reading for tag '" + store.getTagNameForId(index.getTag()) + "' '" + index.getCount() + "' entries of type '" + index.getType().getName() + "'"); } dataObject = TypeFactory .createFromStream(inputStream, index, (i < (indexes.Length - 1)) ? (indexes[i + 1] .getOffset() - index.getOffset()) : (indexDataSize - index.getOffset())); // adjust size size += dataObject.getSize(); store.setTag(index.getTag(), dataObject); } if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer(""); } if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Finished Reading Header"); } }
/** * Set a tag by id as a long * * @param tag * A tag id as a long * @param data * A data struct containing the data of this tag */ public void setTag(long tag, DataTypeIf data) { setTag(new java.lang.Long(tag), data); }
/** * Set a tag by id as a Long * * @param tag * A tag id as a Long * @param data * A data struct containing the data of this tag */ public void setTag(java.lang.Long tag, DataTypeIf data) { isValidTag(tag.longValue()); store.put(tag, data); }
/** * Set a tag by id as a string * * @param tagname * A tag id as a string * @param data * A data struct containing the data of this tag */ public void setTag(String tagname, DataTypeIf data) { setTag(getTagIdForName(tagname), data); }
/** * Read informations of a rpm file out of an input stream. * * @param rpmInputStream The input stream representing the rpm file * @throws IOException if an error occurs during read of the rpm file */ private void readFromStream(java.io.InputStream rpmInputStream) {//throws IOException { ByteCountInputStream allCountInputStream = new ByteCountInputStream( rpmInputStream); java.io.InputStream inputStream = new java.io.DataInputStream(allCountInputStream); lead = new RPMLead((java.io.DataInputStream)inputStream); signature = new RPMSignature((java.io.DataInputStream)inputStream, store); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Signature Size: " + signature.getSize()); } header = new RPMHeader((java.io.DataInputStream)inputStream, store); if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Header Size: " + header.getSize()); } DataTypeIf payloadTag = getTag("PAYLOADFORMAT"); String payloadFormat = payloadTag != null?payloadTag.toString() : "cpio"; DataTypeIf payloadCompressionTag = getTag("PAYLOADCOMPRESSOR"); String payloadCompressor = payloadCompressionTag != null?payloadCompressionTag .toString() : "gzip"; if (payloadFormat.equals("cpio")) { if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("PAYLOADCOMPRESSOR: " + payloadCompressor); } if (payloadCompressor.equals("gzip")) { inputStream = new GzipCompressorInputStream(allCountInputStream); } else if (payloadCompressor.equals("bzip2")) { inputStream = new BZip2CompressorInputStream(allCountInputStream); } else if (payloadCompressor.equals("lzma")) { try { java.io.PipedOutputStream pout = new java.io.PipedOutputStream(); inputStream = new java.io.PipedInputStream(pout); byte[] properties = new byte[5]; if (allCountInputStream.read(properties, 0, 5) != 5) { throw (new java.io.IOException("input .lzma is too short")); } SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder(); decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = allCountInputStream.read(); if (v < 0) { throw (new java.io.IOException("lzma error : Can't Read 1")); } outSize |= ((long)v) << (8 * i); } if (outSize == -1) { outSize = java.lang.Long.MAX_VALUE; } Decode decoderRunnable = new Decode(decoder, allCountInputStream, pout, outSize); java.lang.Thread t = new java.lang.Thread(decoderRunnable, "LZMA Decoder"); t.start(); } catch (java.lang.NoClassDefFoundError) { String message = "No LZMA library found. Attach p7zip library to classpath (http://p7zip.sourceforge.net/)"; logger.severe(message); throw new java.io.IOException(message); } } else if (payloadCompressor.equals("none")) { inputStream = allCountInputStream; } else { throw new java.io.IOException("Unsupported compressor type " + payloadCompressor); } ByteCountInputStream countInputStream = new ByteCountInputStream(inputStream); CpioArchiveInputStream cpioInputStream = new CpioArchiveInputStream(countInputStream); CpioArchiveEntry readEntry; java.util.List <String> fileNamesList = new java.util.ArrayList <String>(); String fileEntry; while ((readEntry = cpioInputStream.getNextCPIOEntry()) != null) { if (logger.isLoggable(java.util.logging.Level.FINER)) { logger.finer("Read CPIO entry: " + readEntry.getName() + " ;mode:" + readEntry.getMode()); } if (readEntry.isRegularFile() || readEntry.isSymbolicLink() || readEntry.isDirectory()) { fileEntry = readEntry.getName(); if (fileEntry.startsWith("./")) { fileEntry = fileEntry.substring(1); } fileNamesList.add(fileEntry); } } store.setTag("FILENAMES", TypeFactory.createSTRING_ARRAY((String[])fileNamesList.toArray(new String[fileNamesList.size()]))); setHeaderTagFromSignature("ARCHIVESIZE", "PAYLOADSIZE"); // check ARCHIVESIZE with countInputStream.getCount(); Object archiveSizeObject = getTag("ARCHIVESIZE"); if (archiveSizeObject != null) { if (archiveSizeObject is INT32) { int archiveSize = ((INT32)archiveSizeObject).getData()[0]; if (archiveSize != countInputStream.getCount()) { new java.io.IOException("ARCHIVESIZE not correct"); } } } store.setTag("J_ARCHIVESIZE", TypeFactory .createINT64(new long[] { countInputStream.getCount() })); } else { throw new java.io.IOException("Unsupported Payload type " + payloadFormat); } // filling in signatures // TODO: check signatures! setHeaderTagFromSignature("SIGSIZE", "SIZE"); setHeaderTagFromSignature("SIGLEMD5_1", "LEMD5_1"); setHeaderTagFromSignature("SIGPGP", "PGP"); setHeaderTagFromSignature("SIGLEMD5_2", "LEMD5_2"); setHeaderTagFromSignature("SIGMD5", "MD5"); setHeaderTagFromSignature("SIGGPG", "GPG"); setHeaderTagFromSignature("SIGPGP5", "PGP5"); setHeaderTagFromSignature("DSAHEADER", "DSA"); setHeaderTagFromSignature("RSAHEADER", "RSA"); setHeaderTagFromSignature("SHA1HEADER", "SHA1"); store.setTag("J_FILESIZE", TypeFactory .createINT64(new long[] { allCountInputStream.getCount() })); rpmInputStream.close(); }