コード例 #1
0
        public void PrintDoubleLetterStatistic_RusVowel()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("ДвойныыеБууквыУУу");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintDoubleLetterStatistic(printer, CharType.Vowel);

            var oneLetter = printer.lettersPrintered[0];

            Assert.AreEqual('Ы', oneLetter.Letter);
            Assert.AreEqual(1, oneLetter.Count);

            oneLetter = printer.lettersPrintered[1];
            Assert.AreEqual('У', oneLetter.Letter);
            Assert.AreEqual(2, oneLetter.Count);
        }
コード例 #2
0
        protected Stream GetCryptoStream(Stream plainStream)
        {
            if ((Header.CompressedSize == 0)
#if !NO_CRYPTO
                && ((Header.PkwareTraditionalEncryptionData != null) ||
                    (Header.WinzipAesEncryptionData != null)))
#else
                && (Header.PkwareTraditionalEncryptionData != null))
#endif
            {
                throw new NotSupportedException("Cannot encrypt file with unknown size at start.");
            }
            if ((Header.CompressedSize == 0) &&
                FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor))
            {
                plainStream = new NonDisposingStream(plainStream); //make sure AES doesn't close
            }
            else
            {
                plainStream = new ReadOnlyStream(plainStream, Header.CompressedSize); //make sure AES doesn't close
            }
            if (Header.PkwareTraditionalEncryptionData != null)
            {
                return(new PkwareTraditionalCryptoStream(plainStream, Header.PkwareTraditionalEncryptionData,
                                                         CryptoMode.Decrypt));
            }
#if !NO_FILE
            if (Header.WinzipAesEncryptionData != null)
            {
                //only read 10 less because the last ten are auth bytes
                return(new WinzipAesCryptoStream(plainStream, Header.WinzipAesEncryptionData, Header.CompressedSize - 10));
            }
#endif
            return(plainStream);
        }
コード例 #3
0
        internal override bool TryRetrieve(string key, out RequestCacheEntry cacheEntry, out Stream readStream)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            FrozenCacheEntry clonedObject = this._Entry;

            cacheEntry = null;
            readStream = null;
            if ((clonedObject == null) || (clonedObject.Key != key))
            {
                Stream            stream;
                RequestCacheEntry entry2;
                if (!this._UseWinInet || !base.TryRetrieve(key, out entry2, out stream))
                {
                    return(false);
                }
                clonedObject = new FrozenCacheEntry(key, entry2, stream);
                stream.Close();
                this._Entry = clonedObject;
            }
            cacheEntry = FrozenCacheEntry.Create(clonedObject);
            readStream = new ReadOnlyStream(clonedObject.StreamBytes);
            return(true);
        }
コード例 #4
0
 public void StreamExtensions_Unit_CopyTo1_InstanceDisposed()
 {
     Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
     Stream stream = new WriteOnlyStream();
     instance.Dispose();
     StreamExtensions.CopyTo(instance, stream);
 }
コード例 #5
0
        public void PrintSingleLetterStatistic_Eng()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("aicaiiBifB");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintSingleLetterStatistic(printer, CharType.Vowel);

            var oneLetter = printer.lettersPrintered[0];

            Assert.AreEqual('a', oneLetter.Letter);
            Assert.AreEqual(2, oneLetter.Count);

            oneLetter = printer.lettersPrintered[1];
            Assert.AreEqual('i', oneLetter.Letter);
            Assert.AreEqual(4, oneLetter.Count);
        }
コード例 #6
0
        public static async Task <List <Changeset> > EventStoreReadChangeset(this IPersistence persistence, String partitionId)
        {
            Recorder tape   = new Recorder();
            var      stream = new ReadOnlyStream(partitionId, persistence);
            await stream.ReadAsync(tape, 1).ConfigureAwait(false);

            return(tape.Data.OfType <Changeset>().ToList());
        }
コード例 #7
0
        public void should_use_explict_interface_impl_if_you_want_to_hide_something_for_certain_type()
        {
            var readOnlyStreamWithWriteExplicitlyImpl = new ReadOnlyStream();

            var hasWriteMethod = readOnlyStreamWithWriteExplicitlyImpl.HasInstanceMethod(
                "Write",
                new[] { typeof(string) });

            // change the variable value to fix the test.
            const bool expectedHasWriteMethod = false;

            Assert.Equal(expectedHasWriteMethod, hasWriteMethod);
        }
コード例 #8
0
        public void should_invoke_explicitly_implemented_method_by_original_interface()
        {
            var readOnlyStreamWithWriteExplicitlyImpl = new ReadOnlyStream();
            var castedToInterface = (ITextStream)readOnlyStreamWithWriteExplicitlyImpl;

            castedToInterface.Write("Hehe");
            var readResult = readOnlyStreamWithWriteExplicitlyImpl.Read();

            // change the variable value to fix the test.
            const string expectedReadResult = "Hehe";

            Assert.Equal(expectedReadResult, readResult);
        }
コード例 #9
0
        public void should_invoke_explicitly_implemented_method_by_original_interface()
        {
            // declare a sub class instance then cast it into base class, so the write method
            // belongs to base class
            var readOnlyStreamWithWriteExplicitlyImpl = new ReadOnlyStream();
            var castedToInterface = (ITextStream)readOnlyStreamWithWriteExplicitlyImpl;

            castedToInterface.Write("Hehe");
            var readResult = readOnlyStreamWithWriteExplicitlyImpl.Read();

            // change the variable value to fix the test.
            const string expectedReadResult = "Hehe";

            Assert.Equal(expectedReadResult, readResult);
        }
コード例 #10
0
        public void FtpFileReadTest()
        {
            ReadOnlyFile ftpFile = new ReadOnlyFile("ftp://speedtest.tele2.net/1KB.zip");

            using (ReadOnlyStream s = ftpFile.Open())
            {
                byte[] data = s.ReadAllBytes();
                Assert.AreEqual(data.Length, 0x400);
                Assert.IsFalse(s.CanWrite);

                var temp = Utility.GetTempFilePath();
                ftpFile.Copy(temp);
                Assert.IsTrue(data.IsEqual(File.ReadAllBytes(temp)));
                File.Delete(temp);
            }
        }
コード例 #11
0
        public void LocalFileReadTest()
        {
            ReadOnlyFile localFile = new ReadOnlyFile(@"C:\Windows\notepad.exe");

            using (ReadOnlyStream s = localFile.Open())
            {
                byte[] data = s.ReadAllBytes();
                Assert.IsTrue(s.Length > 0);
                Assert.AreEqual(data.Length, s.Length);
                Assert.IsFalse(s.CanWrite);

                var temp = Utility.GetTempFilePath();
                localFile.Copy(temp);
                Assert.IsTrue(data.IsEqual(File.ReadAllBytes(temp)));
                File.Delete(temp);
            }
        }
コード例 #12
0
        public void PrintDoubleLetterStatistic_NotDouble()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("A1A");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintDoubleLetterStatistic(printer, CharType.Vowel);

            Assert.AreEqual(0, printer.lettersPrintered.Count);
        }
コード例 #13
0
        public void PrintSingleLetterStatistic_SkipNumber()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("aica123");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintSingleLetterStatistic(printer, CharType.Consonants);

            Assert.AreEqual(1, printer.lettersPrintered.Count);
        }
コード例 #14
0
ファイル: SinFileInfo.cs プロジェクト: vaginessa/ROMExplorer
        public static Stream DecodeTarSin(Stream stream, long totalSize)
        {
            var tarStream = new ReadOnlyStream(stream); // to track Position
            var tarReader = TarReader.Open(tarStream);

            var outStream = TempFileStream.Create();

            while (tarReader.MoveToNextEntry())
            {
                using (var s = new ReadOnlyStream(tarReader.OpenEntryStream()))
                {
                    var sparseStream = new SonySparseStream(s);
                    sparseStream.CopyToEx(outStream, () => { ReportProgress(tarStream.Position, totalSize); });
                }
            }

            return(outStream);
        }
コード例 #15
0
        public void should_use_explict_interface_impl_if_you_want_to_hide_something_for_certain_type()
        {
            // ReadOnlyStream implement ITextStream, explicity implement Write
            // lets the two methods coexist in one class.
            // The only way to call an explicitly implemented member is to cast to its interface
            // as the next test
            var readOnlyStreamWithWriteExplicitlyImpl = new ReadOnlyStream();

            // see if reafOnlyStreamWithExplicitImpl has write method
            var hasWriteMethod = readOnlyStreamWithWriteExplicitlyImpl.HasInstanceMethod(
                "Write",
                new[] { typeof(string) });

            // change the variable value to fix the test.
            const bool expectedHasWriteMethod = false;

            Assert.Equal(expectedHasWriteMethod, hasWriteMethod);
        }
コード例 #16
0
        public void PrintSingleLetterStatistic_EngRemoveNotConsonants()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("aicaiiBifB");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintSingleLetterStatistic(printer, CharType.Consonants);

            var oneLetter = printer.lettersPrintered[0];

            Assert.AreEqual(3, printer.lettersPrintered.Count);
        }
コード例 #17
0
        internal override bool TryRetrieve(string key, out RequestCacheEntry cacheEntry, out Stream readStream)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            FrozenCacheEntry chkEntry = _Entry;

            cacheEntry = null;
            readStream = null;

            if (chkEntry == null || chkEntry.Key != key)
            {
                return(false);
            }
            cacheEntry = FrozenCacheEntry.Create(chkEntry);
            readStream = new ReadOnlyStream(chkEntry.StreamBytes);
            return(true);
        }
コード例 #18
0
        public void PrintSingleLetterStatistic_RusVowel()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("ПриведМедвед");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintSingleLetterStatistic(printer, CharType.Vowel);

            var oneLetter = printer.lettersPrintered[1];

            Assert.AreEqual('е', oneLetter.Letter);
            Assert.AreEqual(3, oneLetter.Count);
        }
コード例 #19
0
		private bool Handler(string method, string uri, HttpHeaders headers, SocketReader reader, Socket socket)
		{
			if (_handlers.Count == 0)
				return false;
			
			string path, querystring;
			int qindex = uri.IndexOf('?');
			if (qindex < 0)
			{
				path = uri;
				querystring = null;
			}
			else
			{
				path = uri.Substring(0, qindex);
				querystring = qindex == (uri.Length - 1) ? "" : uri.Substring(qindex + 1);
			}
			
			MemoryStream requestBodyStream = new MemoryStream();
			byte[] buffer = new byte[8192];
			int bytesRead;
			while (0 != (bytesRead = reader.Read(buffer, 0, buffer.Length)))
			{
				requestBodyStream.Write(buffer, 0, bytesRead);
			}
			requestBodyStream.Seek(0, SeekOrigin.Begin);
			
			Stream readOnlyRequestBodyStream = new ReadOnlyStream(requestBodyStream);
			readOnlyRequestBodyStream.Seek(0, SeekOrigin.Begin);

			Request request = new Request(method, path, querystring, headers, readOnlyRequestBodyStream);
			Response response = new Response(new MemoryStream());
			if (StartFilter.Filter(request, response))
			{
				response.Stream.Seek(0, SeekOrigin.Begin);
				StreamHelper.Transfer(response.Stream, new SocketStream(socket, false));
				return true;
			}
			return false;
		}
コード例 #20
0
        public void PrintDoubleLetterStatistic_SkipSpace()
        {
            var ms     = new MemoryStream();
            var writer = new StreamWriter(ms);

            writer.Write("шш  ШШ  ");
            writer.Flush();

            ms.Seek(0, SeekOrigin.Begin);

            var reader   = new ReadOnlyStream(ms);
            var analyzer = new LetterAnalyzer(reader);
            var printer  = new LetterPrinterToList();

            analyzer.PrintDoubleLetterStatistic(printer, CharType.Consonants);

            var oneLetter = printer.lettersPrintered[0];

            Assert.AreEqual('Ш', oneLetter.Letter);
            Assert.AreEqual(2, oneLetter.Count);
            Assert.AreEqual(1, printer.lettersPrintered.Count);
        }
コード例 #21
0
 public void Dispose()
 {
     ReadOnlyStream.SafeDispose();
 }
コード例 #22
0
ファイル: BufferedStreamTest.cs プロジェクト: nlhepler/mono
	public void WriteByte_CantWrite () 
	{
		ReadOnlyStream ro = new ReadOnlyStream ();
		BufferedStream stream = new BufferedStream (ro);
		stream.WriteByte (0);
	}
コード例 #23
0
		public void SetUp()
		{
			m_memStream = new MemoryStream(m_abyStreamData, true);
			m_stream = new ReadOnlyStream(m_memStream);
		}
コード例 #24
0
        public void StreamExtensions_Unit_CopyTo1_Optimal()
        {
            Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
            Stream stream = new WriteOnlyStream();
            StreamExtensions.CopyTo(instance, stream);

            Assert.AreEqual(StreamContents, Encoding.Unicode.GetString(((MemoryStream)stream).ToArray()));
        }
コード例 #25
0
		public void ConstructorNull()
		{
			Assert.Throws<ArgumentNullException>(() => { ReadOnlyStream stream = new ReadOnlyStream(null); });
		}
コード例 #26
0
 public void StreamExtensions_Unit_CopyTo2_StreamNull()
 {
     Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
     Stream stream = null;
     Int32 bufferSize = 100;
     StreamExtensions.CopyTo(instance, stream, bufferSize);
 }
コード例 #27
0
 public void StreamExtensions_Unit_CopyTo2_StreamDisposed()
 {
     Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
     Stream stream = new WriteOnlyStream();
     Int32 bufferSize = 100;
     stream.Dispose();
     StreamExtensions.CopyTo(instance, stream, bufferSize);
 }
コード例 #28
0
 public void StreamExtensions_Unit_CopyTo2_BufferSizeLessThan1()
 {
     Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
     Stream stream = new WriteOnlyStream();
     Int32 bufferSize = 0;
     StreamExtensions.CopyTo(instance, stream, bufferSize);
 }
コード例 #29
0
	public void Write_CantWrite () 
	{
		ReadOnlyStream ro = new ReadOnlyStream ();
		BufferedStream stream = new BufferedStream (ro);
		stream.Write (new byte [1], 0, 1);
	}
コード例 #30
0
 public Message(int code, ReadOnlyStream stream)
 {
     Code           = code;
     InternalStream = null;
     Stream         = stream;
 }
コード例 #31
0
 public Message()
 {
     Code           = default;
     InternalStream = new MemoryStream();
     Stream         = new ReadOnlyStream(InternalStream);
 }
コード例 #32
0
 public void SetUp()
 {
     m_memStream = new MemoryStream(m_abyStreamData, true);
     m_stream    = new ReadOnlyStream(m_memStream);
 }
コード例 #33
0
        private RarHeader ReadNextHeader(Stream stream)
        {
#if !NO_CRYPTO
            var reader = new RarCryptoBinaryReader(stream, Password);

            if (IsEncrypted)
            {
                if (Password == null)
                {
                    throw new CryptographicException("Encrypted Rar archive has no password specified.");
                }
                reader.SkipQueue();
                byte[] salt = reader.ReadBytes(8);
                reader.InitializeAes(salt);
            }
#else
            var reader = new MarkingBinaryReader(stream);
#endif

            RarHeader header = RarHeader.Create(reader);
            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderType)
            {
            case HeaderType.ArchiveHeader:
            {
                var ah = header.PromoteHeader <ArchiveHeader>(reader);
                IsEncrypted = ah.HasPassword;
                return(ah);
            }

            case HeaderType.MarkHeader:
            {
                return(header.PromoteHeader <MarkHeader>(reader));
            }

            case HeaderType.ProtectHeader:
            {
                ProtectHeader ph = header.PromoteHeader <ProtectHeader>(reader);

                // skip the recovery record data, we do not use it.
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    reader.BaseStream.Position += ph.DataSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    reader.BaseStream.Skip(ph.DataSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }

                return(ph);
            }

            case HeaderType.NewSubHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    //skip the data because it's useless?
                    reader.BaseStream.Skip(fh.CompressedSize);
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.FileHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    var ms = new ReadOnlyStream(reader.BaseStream, fh.CompressedSize);
                    if (fh.Salt == null)
                    {
                        fh.PackedStream = ms;
                    }
                    else
                    {
#if !NO_CRYPTO
                        fh.PackedStream = new RarCryptoWrapper(ms, Password, fh.Salt);
#else
                        throw new NotSupportedException("RarCrypto not supported");
#endif
                    }
                }
                break;

                default:
                {
                    throw new InvalidFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.EndArchiveHeader:
            {
                return(header.PromoteHeader <EndArchiveHeader>(reader));
            }

            default:
            {
                throw new InvalidFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
            }
            }
        }
コード例 #34
0
 public Message(int code, System.IO.Stream stream)
 {
     Code           = code;
     InternalStream = null;
     Stream         = new ReadOnlyStream(stream);
 }
コード例 #35
0
 public void StreamExtensions_Unit_CopyTo1_StreamNull()
 {
     Stream instance = new ReadOnlyStream(Encoding.Unicode.GetBytes(StreamContents));
     Stream stream = null;
     StreamExtensions.CopyTo(instance, stream);
 }
コード例 #36
0
 public Message(IConvertible code, System.IO.Stream stream)
 {
     Code           = Convert.ToInt32(code);
     InternalStream = null;
     Stream         = new ReadOnlyStream(stream);
 }
コード例 #37
0
 public void ConstructorNull()
 {
     Assert.Throws <ArgumentNullException>(() => { ReadOnlyStream stream = new ReadOnlyStream(null); });
 }