Exemplo n.º 1
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual ByteArrayWindow Read(long pos, int size)
 {
     lock (readLock)
     {
         if (length < pos + size)
         {
             size = (int)(length - pos);
         }
         byte[] buf = new byte[size];
         fd.Seek(pos);
         fd.ReadFully(buf, 0, size);
         return(new ByteArrayWindow(this, pos, buf));
     }
 }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        public static FsImageProto.FileSummary LoadSummary(RandomAccessFile file)
        {
            int  FileLengthFieldSize = 4;
            long fileLength          = file.Length();

            file.Seek(fileLength - FileLengthFieldSize);
            int summaryLength = file.ReadInt();

            if (summaryLength <= 0)
            {
                throw new IOException("Negative length of the file");
            }
            file.Seek(fileLength - FileLengthFieldSize - summaryLength);
            byte[] summaryBytes = new byte[summaryLength];
            file.ReadFully(summaryBytes);
            FsImageProto.FileSummary summary = FsImageProto.FileSummary.ParseDelimitedFrom(new
                                                                                           ByteArrayInputStream(summaryBytes));
            if (summary.GetOndiskVersion() != FileVersion)
            {
                throw new IOException("Unsupported file version " + summary.GetOndiskVersion());
            }
            if (!NameNodeLayoutVersion.Supports(LayoutVersion.Feature.ProtobufFormat, summary
                                                .GetLayoutVersion()))
            {
                throw new IOException("Unsupported layout version " + summary.GetLayoutVersion());
            }
            return(summary);
        }
Exemplo n.º 3
0
        public static byte [] readFile(Java.IO.File file)
        {
            // Open file
            var f = new RandomAccessFile(file, "r");

            try {
                // Get and check length
                long longlength = f.Length();
                var  length     = (int)longlength;

                if (length != longlength)
                {
                    throw new Java.IO.IOException("Filesize exceeds allowed size");
                }
                // Read file and return data
                byte [] data = new byte [length];
                f.ReadFully(data);
                return(data);
            } catch (Exception ex) {
                System.Diagnostics.Debug.Write(ex);
                return(new byte [0]);
            } finally {
                f.Close();
            }
        }
Exemplo n.º 4
0
        public static byte[] ReadFileFromPath(File file)
        {
            // Open file
            var f = new RandomAccessFile(file, "r");

            try
            {
                // Get and check length
                var longlength = f.Length();
                var length     = (int)longlength;
                if (length != longlength)
                {
                    throw new IOException("Tamanho do arquivo excede o permitido!");
                }
                // Read file and return data
                var data = new byte[length];
                f.ReadFully(data);
                return(data);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
                return(null);
            }
            finally
            {
                f.Close();
                f.Dispose();
            }
        }
Exemplo n.º 5
0
        public static byte[] readFile(File file)
        {
            // Open file
            var f = new RandomAccessFile(file, "r");

            try
            {
                // Get and check length
                long longlength = f.Length();
                var  length     = (int)longlength;

                if (length != longlength)
                {
                    throw new IOException("Filesize exceeds allowed size");
                }
                // Read file and return data
                byte[] data = new byte[length];
                f.ReadFully(data);
                return(data);
            }
            finally
            {
                f.Close();
            }
        }
Exemplo n.º 6
0
        public static byte[] readFile(Java.IO.File file)
        {
            // Open file
            RandomAccessFile f = new RandomAccessFile(file, "r");

            try
            {
                // Get and check length
                long longlength = f.Length();
                int  length     = (int)longlength;
                if (length != longlength)
                {
                    throw new Java.IO.IOException("Tamanho do arquivo excede o permitido!");
                }
                // Read file and return data
                byte[] data = new byte[length];
                f.ReadFully(data);
                return(data);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
                return(new byte[0]);
            }
            finally
            {
                f.Close();
            }
        }
Exemplo n.º 7
0
 /// <summary>Read the header at the beginning of the given block meta file.</summary>
 /// <remarks>
 /// Read the header at the beginning of the given block meta file.
 /// The current file position will be altered by this method.
 /// If an error occurs, the file is <em>not</em> closed.
 /// </remarks>
 /// <exception cref="System.IO.IOException"/>
 public static Org.Apache.Hadoop.Hdfs.Server.Datanode.BlockMetadataHeader ReadHeader
     (RandomAccessFile raf)
 {
     byte[] buf = new byte[GetHeaderSize()];
     raf.Seek(0);
     raf.ReadFully(buf, 0, buf.Length);
     return(ReadHeader(new DataInputStream(new ByteArrayInputStream(buf))));
 }
Exemplo n.º 8
0
        //private static String readInstallationFile(File installation)
        //{
        //    RandomAccessFile f = new RandomAccessFile(installation, "r");
        //    byte[] bytes = new byte[(int)f.Length()];
        //    f.ReadFully(bytes);
        //    f.Close();
        //    return new Java.Lang.String(bytes).ToString();
        //}
        private static String readInstallationFile(Java.IO.File installation)
        {
            RandomAccessFile f = new RandomAccessFile(installation, "r");

            byte[] bytes = new byte[(int)f.Length()];
            f.ReadFully(bytes);
            f.Close();
            return(new Java.Lang.String(bytes).ToString());
        }
Exemplo n.º 9
0
        private static string readInstallationFile(File installation)
        {
            RandomAccessFile f = new RandomAccessFile(installation, "r");

            byte[] bytes = new byte[(int)f.Length()];
            f.ReadFully(bytes);
            f.Close();
            System.Text.UTF8Encoding en = new UTF8Encoding();
            return(en.GetString(bytes));
        }
Exemplo n.º 10
0
 /// <exception cref="System.IO.IOException"/>
 public static bool CheckFileFormat(RandomAccessFile file)
 {
     if (file.Length() < FSImageFormatProtobuf.Loader.MinimumFileLength)
     {
         return(false);
     }
     byte[] magic = new byte[MagicHeader.Length];
     file.ReadFully(magic);
     if (!Arrays.Equals(MagicHeader, magic))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Reads installation ID from file.
        /// </summary>
        /// <param name="installation"><see cref="File"/> to read ID from</param>
        /// <returns>Application installation ID</returns>
        private static string ReadInstallationFile(File installation)
        {
            var f     = new RandomAccessFile(installation, "r");
            var bytes = new byte[(int)f.Length()];

            try
            {
                f.ReadFully(bytes);
            }
            finally
            {
                f.Close();
            }
            return(Encoding.UTF8.GetString(bytes));
        }
Exemplo n.º 12
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal override void OnEndThinPack()
        {
            byte[]        tailHash      = this.tailDigest.Digest();
            byte[]        buf           = Buffer();
            MessageDigest origDigest    = Constants.NewMessageDigest();
            MessageDigest tailDigest    = Constants.NewMessageDigest();
            MessageDigest packDigest    = Constants.NewMessageDigest();
            long          origRemaining = origEnd;

            @out.Seek(0);
            @out.ReadFully(buf, 0, 12);
            origDigest.Update(buf, 0, 12);
            origRemaining -= 12;
            NB.EncodeInt32(buf, 8, GetObjectCount());
            @out.Seek(0);
            @out.Write(buf, 0, 12);
            packDigest.Update(buf, 0, 12);
            for (; ;)
            {
                int n = @out.Read(buf);
                if (n < 0)
                {
                    break;
                }
                if (origRemaining != 0)
                {
                    int origCnt = (int)Math.Min(n, origRemaining);
                    origDigest.Update(buf, 0, origCnt);
                    origRemaining -= origCnt;
                    if (origRemaining == 0)
                    {
                        tailDigest.Update(buf, origCnt, n - origCnt);
                    }
                }
                else
                {
                    tailDigest.Update(buf, 0, n);
                }
                packDigest.Update(buf, 0, n);
            }
            if (!Arrays.Equals(origDigest.Digest(), origHash) || !Arrays.Equals(tailDigest.Digest
                                                                                    (), tailHash))
            {
                throw new IOException(JGitText.Get().packCorruptedWhileWritingToFilesystem);
            }
            packHash = packDigest.Digest();
        }