Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        public SpillRecord(Path indexFileName, JobConf job, Checksum crc, string expectedIndexOwner
                           )
        {
            FileSystem        rfs = FileSystem.GetLocal(job).GetRaw();
            FSDataInputStream @in = SecureIOUtils.OpenFSDataInputStream(new FilePath(indexFileName
                                                                                     .ToUri().GetRawPath()), expectedIndexOwner, null);

            try
            {
                long length     = rfs.GetFileStatus(indexFileName).GetLen();
                int  partitions = (int)length / MapTask.MapOutputIndexRecordLength;
                int  size       = partitions * MapTask.MapOutputIndexRecordLength;
                buf = ByteBuffer.Allocate(size);
                if (crc != null)
                {
                    crc.Reset();
                    CheckedInputStream chk = new CheckedInputStream(@in, crc);
                    IOUtils.ReadFully(chk, ((byte[])buf.Array()), 0, size);
                    if (chk.GetChecksum().GetValue() != @in.ReadLong())
                    {
                        throw new ChecksumException("Checksum error reading spill index: " + indexFileName
                                                    , -1);
                    }
                }
                else
                {
                    IOUtils.ReadFully(@in, ((byte[])buf.Array()), 0, size);
                }
                entries = buf.AsLongBuffer();
            }
            finally
            {
                @in.Close();
            }
        }
        private const int FCOMMENT = 16;     // File comment

        /*
         * Reads GZIP member header and returns the total byte number
         * of this member header.
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private int readHeader(java.io.InputStream this_in) throws java.io.IOException
        private int ReadHeader(InputStream this_in)
        {
            CheckedInputStream @in = new CheckedInputStream(this_in, Crc);

            Crc.Reset();
            // Check header magic
            if (ReadUShort(@in) != GZIP_MAGIC)
            {
                throw new ZipException("Not in GZIP format");
            }
            // Check compression method
            if (ReadUByte(@in) != 8)
            {
                throw new ZipException("Unsupported compression method");
            }
            // Read flags
            int flg = ReadUByte(@in);

            // Skip MTIME, XFL, and OS fields
            SkipBytes(@in, 6);
            int n = 2 + 2 + 6;

            // Skip optional extra field
            if ((flg & FEXTRA) == FEXTRA)
            {
                int m = ReadUShort(@in);
                SkipBytes(@in, m);
                n += m + 2;
            }
            // Skip optional file name
            if ((flg & FNAME) == FNAME)
            {
                do
                {
                    n++;
                } while (ReadUByte(@in) != 0);
            }
            // Skip optional file comment
            if ((flg & FCOMMENT) == FCOMMENT)
            {
                do
                {
                    n++;
                } while (ReadUByte(@in) != 0);
            }
            // Check optional header CRC
            if ((flg & FHCRC) == FHCRC)
            {
                int v = (int)Crc.Value & 0xffff;
                if (ReadUShort(@in) != v)
                {
                    throw new ZipException("Corrupt GZIP header");
                }
                n += 2;
            }
            Crc.Reset();
            return(n);
        }
 public RawInput(Stream stream, bool validateAdler)
 {
     if (validateAdler)
     {
         this._checkedStream = new CheckedInputStream(stream, new Adler32());
         this.stream = _checkedStream;
     }
     else
     {
         this.stream = stream;
         this._checkedStream = null;
     }
     //this.dis = new BinaryReader(this.stream);
 }
Beispiel #4
0
 public RawInput(Stream stream, bool validateAdler)
 {
     if (validateAdler)
     {
         this._checkedStream = new CheckedInputStream(stream, new Adler32());
         this.stream         = _checkedStream;
     }
     else
     {
         this.stream         = stream;
         this._checkedStream = null;
     }
     //this.dis = new BinaryReader(this.stream);
 }