OpenRead() public static method

public static OpenRead ( IOConnectionInfo ioc ) : Stream
ioc IOConnectionInfo
return Stream
コード例 #1
0
        public static byte[] ReadFile(IOConnectionInfo ioc)
        {
            Stream       sIn = null;
            MemoryStream ms  = null;

            try
            {
                sIn = IOConnection.OpenRead(ioc);
                if (sIn == null)
                {
                    return(null);
                }

                ms = new MemoryStream();
                MemUtil.CopyStream(sIn, ms);

                return(ms.ToArray());
            }
            catch (Exception) { }
            finally
            {
                if (sIn != null)
                {
                    sIn.Close();
                }
                if (ms != null)
                {
                    ms.Close();
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: FileLock.cs プロジェクト: nagyist/mackeepass
            public static LockFileInfo Load(IOConnectionInfo iocLockFile)
            {
                Stream s = null;

                try
                {
                    s = IOConnection.OpenRead(iocLockFile);
                    if (s == null)
                    {
                        return(null);
                    }
                    StreamReader sr  = new StreamReader(s, StrUtil.Utf8);
                    string       str = sr.ReadToEnd();
                    sr.Close();
                    if (str == null)
                    {
                        Debug.Assert(false);
                        return(null);
                    }

                    str = StrUtil.NormalizeNewLines(str, false);
                    string[] v = str.Split('\n');
                    if ((v == null) || (v.Length < 6))
                    {
                        Debug.Assert(false);
                        return(null);
                    }

                    if (!v[0].StartsWith(LockFileHeader))
                    {
                        Debug.Assert(false);
                        return(null);
                    }
                    return(new LockFileInfo(v[1], v[2], v[3], v[4], v[5]));
                }
                catch (FileNotFoundException)
                {
                }
                catch (Exception)
                {
                    Debug.Assert(false);
                }
                finally
                {
                    if (s != null)
                    {
                        s.Close();
                    }
                }

                return(null);
            }
コード例 #3
0
        public static byte[] ReadFile(IOConnectionInfo ioc)
        {
            try
            {
                using (Stream s = IOConnection.OpenRead(ioc))
                {
                    return(MemUtil.Read(s));
                }
            }
            catch (Exception) { Debug.Assert(false); }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Load a KDBX file.
        /// </summary>
        /// <param name="strFilePath">File to load.</param>
        /// <param name="fmt">Format.</param>
        /// <param name="slLogger">Status logger (optional).</param>
        public void Load(string strFilePath, KdbxFormat fmt, IStatusLogger slLogger)
        {
            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);

            Load(IOConnection.OpenRead(ioc), fmt, slLogger);
        }
コード例 #5
0
        /// <summary>
        /// Load a KDB file from a file.
        /// </summary>
        /// <param name="strFilePath">File to load.</param>
        /// <param name="kdbFormat">Format specifier.</param>
        /// <param name="slLogger">Status logger (optional).</param>
        public void Load(string strFilePath, Kdb4Format kdbFormat, IStatusLogger slLogger)
        {
            IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);

            this.Load(IOConnection.OpenRead(ioc), kdbFormat, slLogger);
        }