Exemplo n.º 1
0
            public void AddFile(JarFileItem jarFileItem)
            {
                var fileCount = GetFileCount();

                using (BinaryWriter writer = new BinaryWriter(File.Open(_logFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)))
                {
                    fileCount++;
                    writer.Seek(0, SeekOrigin.Begin);
                    writer.Write(Encoding.ASCII.GetBytes(fileCount.ToString().PadLeft(FileCountFieldSize)));
                    writer.Seek(0, SeekOrigin.End);

                    var headerString = DicToString(jarFileItem.Headers);

                    var headerBytes = Encoding.ASCII.GetBytes(headerString.PadLeft(HeaderFieldSize));
                    if (headerBytes.Count() > HeaderFieldSize)
                    {
                        throw new Exception("Header out of limit");
                    }

                    writer.Write(headerBytes);
                    writer.Seek(0, SeekOrigin.End);

                    //var fileBytes = File.ReadAllBytes(jarFileItem.FilePath);
                    var fileBytes = jarFileItem.Containt;
                    writer.Write(Encoding.ASCII.GetBytes(fileBytes.Length.ToString().PadLeft(FileLengthFieldSize)));
                    writer.Write(fileBytes);
                }
            }
Exemplo n.º 2
0
        public void AddFile(JarFileItem jarFileItem)
        {
            if (_fileAccessMode == FileAccessMode.Read)
            {
                throw new InvalidOperationException("Append File can not be peromed on read mode");
            }

            if (_writer.GetFileCount() >= _maxFileCount)
            {
                throw new JarFileReachedMaxLimitException();
            }

            _writer.AddFile(jarFileItem);
        }
Exemplo n.º 3
0
        private static JarFileItem BuildOrRetrieveEmptyInstance()
        {
            if (_emptyInstance == null)
            {
                lock (Locker)
                {
                    // double check in case _emptyInstance was instantiated while this thread was locked.
                    if (_emptyInstance == null)
                    {
                        _emptyInstance = new JarFileItem();
                    }
                }
            }

            return(_emptyInstance);
        }