コード例 #1
0
        /**
         * Helper method to verify that the files were archived correctly by reading {@code
         * tarArchiveInputStream}.
         */
        private void VerifyTarArchive(TarInputStream tarArchiveInputStream)
        {
            // Verifies fileA was archived correctly.
            TarEntry headerFileA = tarArchiveInputStream.GetNextEntry();

            Assert.AreEqual("some/path/to/resourceFileA", headerFileA.Name);
            byte[] fileAString = ByteStreams.ToByteArray(tarArchiveInputStream);
            CollectionAssert.AreEqual(fileAContents, fileAString);

            // Verifies fileB was archived correctly.
            TarEntry headerFileB = tarArchiveInputStream.GetNextEntry();

            Assert.AreEqual("crepecake", headerFileB.Name);
            byte[] fileBString = ByteStreams.ToByteArray(tarArchiveInputStream);
            CollectionAssert.AreEqual(fileBContents, fileBString);

            // Verifies directoryA was archived correctly.
            TarEntry headerDirectoryA = tarArchiveInputStream.GetNextEntry();

            Assert.AreEqual("some/path/to/", headerDirectoryA.Name);

            // Verifies the long file was archived correctly.
            TarEntry headerFileALong = tarArchiveInputStream.GetNextEntry();

            Assert.AreEqual(
                "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890",
                headerFileALong.Name);
            byte[] fileALongString = ByteStreams.ToByteArray(tarArchiveInputStream);
            CollectionAssert.AreEqual(fileAContents, fileALongString);

            Assert.IsNull(tarArchiveInputStream.GetNextEntry());
        }
コード例 #2
0
 private byte[] GetContents(IBinaryResource resource)
 {
     using (Stream file = resource.OpenStream())
     {
         byte[] contents = ByteStreams.ToByteArray(file);
         return(contents);
     }
 }
コード例 #3
0
        public void Initialize()
        {
            // Initializes the IFileCache
            _fileCacheFactory = new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory());
            _fileCache        = _fileCacheFactory.Get(DiskCacheConfig.NewBuilder().Build());

            // Initializes the IPooledByteBufferFactory and PooledByteStreams
            _poolFactory       = new PoolFactory(PoolConfig.NewBuilder().Build());
            _byteBufferFactory = _poolFactory.PooledByteBufferFactory;
            _pooledByteStreams = _poolFactory.PooledByteStreams;

            // Initializes the IPooledByteBuffer from an image
            var file = StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/SplashScreen.scale-200.png")).GetAwaiter().GetResult();

            using (var stream = file.OpenReadAsync().GetAwaiter().GetResult())
            {
                _pooledByteBuffer = _byteBufferFactory.NewByteBuffer(
                    ByteStreams.ToByteArray(stream.AsStream()));
            }

            _closeableReference = CloseableReference <IPooledByteBuffer> .of(_pooledByteBuffer);

            _encodedImage           = new EncodedImage(_closeableReference);
            _stagingArea            = StagingArea.Instance;
            _imageCacheStatsTracker = NoOpImageCacheStatsTracker.Instance;

            // Initializes the cache keys
            IList <ICacheKey> keys = new List <ICacheKey>();

            keys.Add(new SimpleCacheKey("http://test.uri"));
            keys.Add(new SimpleCacheKey("http://tyrone.uri"));
            keys.Add(new SimpleCacheKey("http://ian.uri"));
            _cacheKey = new MultiCacheKey(keys);

            // Initializes the executors
            _isCancelled           = new AtomicBoolean(false);
            _readPriorityExecutor  = Executors.NewFixedThreadPool(1);
            _writePriorityExecutor = Executors.NewFixedThreadPool(1);

            // Initializes the disk cache
            _bufferedDiskCache = new BufferedDiskCache(
                _fileCache,
                _byteBufferFactory,
                _pooledByteStreams,
                _readPriorityExecutor,
                _writePriorityExecutor,
                _imageCacheStatsTracker);
        }
コード例 #4
0
 public async Task TestGetAsync()
 {
     using (TestWebServer server = new TestWebServer(false))
         using (Connection connection =
                    Connection.GetConnectionFactory()(new Uri("http://" + server.GetAddressAndPort())))
             using (HttpRequestMessage request = new HttpRequestMessage())
                 using (HttpResponseMessage response = await connection.SendAsync(request).ConfigureAwait(false))
                 {
                     Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
                     using (Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                     {
                         CollectionAssert.AreEqual(
                             Encoding.UTF8.GetBytes("Hello World!"),
                             ByteStreams.ToByteArray(stream));
                     }
                 }
 }
コード例 #5
0
        public async Task TestParseMetaData_PNG()
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/ImagePipeline/Images/image.png"));

            using (var stream = await file.OpenReadAsync())
            {
                IPooledByteBuffer buf = new TrivialPooledByteBuffer(
                    ByteStreams.ToByteArray(stream.AsStream()));

                EncodedImage encodedImage = new EncodedImage(
                    CloseableReference <IPooledByteBuffer> .of(buf, _releaser));

                await encodedImage.ParseMetaDataAsync();

                Assert.AreEqual(ImageFormat.PNG, encodedImage.Format);
                Assert.AreEqual(800, encodedImage.Width);
                Assert.AreEqual(600, encodedImage.Height);
            }
        }
コード例 #6
0
        public async Task TestToBlob_multiByteAsync()
        {
            testTarStreamBuilder.AddByteEntry(Encoding.UTF8.GetBytes("日本語"), "test");
            testTarStreamBuilder.AddByteEntry(Encoding.UTF8.GetBytes("asdf"), "crepecake");
            testTarStreamBuilder.AddBlobEntry(
                Blobs.From("fib"), Encoding.UTF8.GetBytes("fib").Length, "fib");

            // Writes the BLOB and captures the output.
            MemoryStream tarByteOutputStream = new MemoryStream();

            using (Stream compressorStream = new GZipStream(tarByteOutputStream, CompressionMode.Compress))
            {
                await testTarStreamBuilder.WriteAsTarArchiveToAsync(compressorStream).ConfigureAwait(false);
            }

            // Rearrange the output into input for verification.
            MemoryStream byteArrayInputStream =
                new MemoryStream(tarByteOutputStream.ToArray());
            Stream tarByteInputStream = new GZipStream(byteArrayInputStream, CompressionMode.Decompress);

            using (TarInputStream tarArchiveInputStream = new TarInputStream(tarByteInputStream))
            {
                // Verify multi-byte characters are written/read correctly
                TarEntry headerFile = tarArchiveInputStream.GetNextEntry();
                Assert.AreEqual("test", headerFile.Name);
                Assert.AreEqual(
                    "日本語", Encoding.UTF8.GetString(ByteStreams.ToByteArray(tarArchiveInputStream)));

                headerFile = tarArchiveInputStream.GetNextEntry();
                Assert.AreEqual("crepecake", headerFile.Name);
                Assert.AreEqual(
                    "asdf", Encoding.UTF8.GetString(ByteStreams.ToByteArray(tarArchiveInputStream)));

                headerFile = tarArchiveInputStream.GetNextEntry();
                Assert.AreEqual("fib", headerFile.Name);
                Assert.AreEqual(
                    "fib", Encoding.UTF8.GetString(ByteStreams.ToByteArray(tarArchiveInputStream)));

                Assert.IsNull(tarArchiveInputStream.GetNextEntry());
            }
        }