Esempio n. 1
0
        /// <summary>
        ///     Compresses a GZIP file.
        /// </summary>
        /// <param name="bytes"> The uncompressed bytes. </param>
        /// <returns> The compressed bytes. </returns>
        /// <exception cref="IOException"> if an I/O error occurs. </exception>
        public static byte[] Gzip(byte[] bytes)
        {
            /* create the streams */
            var @is = new ByteArrayInputStream(bytes);

            try
            {
                var bout = new ByteArrayOutputStream();
                var os   = new GZIPOutputStream(bout);
                try
                {
                    /* copy data between the streams */
                    var buf = new byte[4096];
                    var len = 0;
                    while ((len = @is.read(buf, 0, buf.Length)) != -1)
                    {
                        os.write(buf, 0, len);
                    }
                }
                finally
                {
                    os.close();
                }

                /* return the compressed bytes */
                return(bout.toByteArray());
            }
            finally
            {
                @is.close();
            }
        }
Esempio n. 2
0
        public override void serializeBody(OutputStream stream)
        {
            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            GZIPOutputStream      stream3 = new GZIPOutputStream(stream2);

            this.method.serialize(stream3);
            stream3.flush();
            stream3.close();
            StreamingUtils.writeTLBytes(stream2.toByteArray(), stream);
        }
Esempio n. 3
0
        private sbyte[] getCompressedPrxFile(string dirName, string fileName)
        {
            string proxyFileName;

            if (string.ReferenceEquals(dirName, null) || dirName.Length == 0)
            {
                proxyFileName = fileName;
            }
            else
            {
                proxyFileName = dirName + "/" + fileName;
            }

            IVirtualFile vFileUncompressed = base.ioOpen(proxyFileName, PSP_O_RDONLY, 0);

            if (vFileUncompressed == null)
            {
                return(null);
            }
            sbyte[] bufferUncompressed = Utilities.readCompleteFile(vFileUncompressed);
            vFileUncompressed.ioClose();
            if (bufferUncompressed == null)
            {
                return(null);
            }

            int headerMagic = Utilities.readUnaligned32(bufferUncompressed, 0);

            if (headerMagic != Elf32Header.ELF_MAGIC)
            {
                return(bufferUncompressed);
            }

            int lengthUncompressed = bufferUncompressed.Length;

            System.IO.MemoryStream osCompressed = new System.IO.MemoryStream(PSP_HEADER_SIZE + 9 + lengthUncompressed);
            try
            {
                writePspHeader(osCompressed, bufferUncompressed, fileName);
                // loadcore.prx and sysmem.prx need to be compressed using KL4E.
                // KL4E supports a version where the data is not compressed.
                // Use this simple version as we have no real KL4E compressor.
                if (isKl4eCompression(fileName))
                {
                    writeString(osCompressed, "KL4E", 4);
                    write8(osCompressed, 0x80);                     // Flag indicating that the rest of the data is uncompressed
                    write32(osCompressed, endianSwap32(lengthUncompressed));
                    writeBytes(osCompressed, bufferUncompressed, lengthUncompressed);
                }
                else
                {
                    GZIPOutputStream os = new GZIPOutputStream(osCompressed);
                    os.write(bufferUncompressed, 0, lengthUncompressed);
                    os.close();
                }
            }
            catch (IOException)
            {
            }

            sbyte[] bytes = osCompressed.toByteArray();
            fixPspSizeInHeader(bytes);

            return(bytes);
        }