Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        public byte[] getAsBinary(string key)
        {
            RandomAccessFile raFile     = null;
            bool             removeFile = false;

            try
            {
                File file = mCache.get(key);

                if (!file.Exists())
                {
                    return(null);
                }

                raFile = new RandomAccessFile(file, "r");
                byte[] byteArray = new byte[(int)raFile.Length()];

                raFile.Read(byteArray);

                if (!Utils.isDue(byteArray))
                {
                    return(Utils.clearDateInfo(byteArray));
                }
                else
                {
                    removeFile = true;

                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                VPNLog.d("ACache", ex.ToString());

                return(null);
            }
            finally
            {
                if (raFile != null)
                {
                    try
                    {
                        raFile.Dispose();
                    }
                    catch (IOException ex)
                    {
                        ex.PrintStackTrace();
                    }
                }

                if (removeFile)
                {
                    remove(key);
                }
            }
        }