예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void writeChars(org.neo4j.io.fs.StoreChannel channel, ByteBuffer buffer, char[] chars) throws java.io.IOException
        private static void WriteChars(StoreChannel channel, ByteBuffer buffer, char[] chars)
        {
            int position = 0;

            do
            {
                buffer.clear();
                int leftToWrite = chars.Length - position;
                if (leftToWrite * 2 < buffer.capacity())
                {
                    buffer.asCharBuffer().put(chars, position, leftToWrite);
                    buffer.limit(leftToWrite * 2);
                    channel.write(buffer);
                    position += leftToWrite;
                }
                else
                {
                    int length = buffer.capacity() / 2;
                    buffer.asCharBuffer().put(chars, position, length);
                    buffer.limit(length * 2);
                    channel.write(buffer);
                    position += length;
                }
            } while (position < chars.Length);
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void write(int b) throws java.io.IOException
        public override void Write(int b)
        {
            _buffer.clear();
            _buffer.put(( sbyte )b);
            _buffer.flip();
            _channel.write(_buffer);
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void readAndWriteMustTakeBufferPositionIntoAccount() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ReadAndWriteMustTakeBufferPositionIntoAccount()
        {
            sbyte[]    bytes = new sbyte[] { 1, 2, 3, 4, 5 };
            ByteBuffer buf   = ByteBuffer.wrap(bytes);

            buf.position(1);

            Fsa.mkdirs(Path);
            File file = new File(Path, "file");

            using (StoreChannel channel = Fsa.open(file, OpenMode.ReadWrite))
            {
                assertThat(channel.write(buf), @is(4));
            }
            using (Stream stream = Fsa.openAsInputStream(file))
            {
                assertThat(stream.Read(), @is(2));
                assertThat(stream.Read(), @is(3));
                assertThat(stream.Read(), @is(4));
                assertThat(stream.Read(), @is(5));
                assertThat(stream.Read(), @is(-1));
            }
            Arrays.fill(bytes, ( sbyte )0);
            buf.position(1);
            using (StoreChannel channel = Fsa.open(file, OpenMode.ReadWrite))
            {
                assertThat(channel.read(buf), @is(4));
                buf.clear();
                assertThat(buf.get(), @is((sbyte)0));
                assertThat(buf.get(), @is((sbyte)2));
                assertThat(buf.get(), @is((sbyte)3));
                assertThat(buf.get(), @is((sbyte)4));
                assertThat(buf.get(), @is((sbyte)5));
            }
        }
예제 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void writeInt(org.neo4j.io.fs.StoreChannel channel, ByteBuffer buffer, int value) throws java.io.IOException
        public static void WriteInt(StoreChannel channel, ByteBuffer buffer, int value)
        {
            buffer.clear();
            buffer.putInt(value);
            buffer.flip();
            channel.write(buffer);
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sendLargeFileWithUnreliableReadBufferSize() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SendLargeFileWithUnreliableReadBufferSize()
        {
            // given
            sbyte[] bytes = new sbyte[MAX_SIZE * 3];
            _random.NextBytes(bytes);

            File smallFile = TestDirectory.file("smallFile");

            using (StoreChannel storeChannel = _fs.create(smallFile))
            {
                storeChannel.write(ByteBuffer.wrap(bytes));
            }

            Adversary adversary = new RandomAdversary(0.9, 0.0, 0.0);
            AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, _fs);
            FileSender fileSender = new FileSender(new StoreResource(smallFile, null, 16, afs));

            // when + then
            assertFalse(fileSender.EndOfInput);
            assertEquals(FileChunk.Create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.ReadChunk(_allocator));
            assertEquals(FileChunk.Create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.ReadChunk(_allocator));
            assertEquals(FileChunk.Create(copyOfRange(bytes, MAX_SIZE * 2, bytes.Length), true), fileSender.ReadChunk(_allocator));
            assertNull(fileSender.ReadChunk(_allocator));
            assertTrue(fileSender.EndOfInput);
        }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void writeLong(org.neo4j.io.fs.StoreChannel channel, long value) throws java.io.IOException
        private static void WriteLong(StoreChannel channel, long value)
        {
            ByteBuffer buffer = allocate(8);

            buffer.putLong(value);
            buffer.flip();
            channel.write(buffer);
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Before()
        {
            _fs        = Fsr.get();
            _pageCache = PageCacheRule.getPageCache(Fsr.get());
            using (StoreChannel channel = _fs.create(_storeFile))
            {
                ByteBuffer buffer = ByteBuffer.allocate(4);
                buffer.putInt(BLOCK_SIZE);
                buffer.flip();
                channel.write(buffer);
            }
        }
예제 #8
0
 private static void WriteContents(FileSystemAbstraction fileSystemAbstraction, File file, string contents)
 {
     sbyte[] bytes = contents.GetBytes();
     try
     {
         using (StoreChannel storeChannel = fileSystemAbstraction.Create(file))
         {
             storeChannel.write(ByteBuffer.wrap(bytes));
         }
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }
예제 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void generateFileWithRecords(java.io.File file, int recordCount) throws java.io.IOException
        private void GenerateFileWithRecords(File file, int recordCount)
        {
            using (StoreChannel channel = Fsa.open(file, OpenMode.ReadWrite))
            {
                ByteBuffer buf = ByteBuffer.allocate(_recordSize);
                for (int i = 0; i < recordCount; i++)
                {
                    GenerateRecordForId(i, buf);
                    int rem = buf.remaining();
                    do
                    {
                        rem -= channel.write(buf);
                    } while (rem > 0);
                }
            }
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sendSmallFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SendSmallFile()
        {
            // given
            sbyte[] bytes = new sbyte[10];
            _random.NextBytes(bytes);

            File smallFile = TestDirectory.file("smallFile");

            using (StoreChannel storeChannel = _fs.create(smallFile))
            {
                storeChannel.write(ByteBuffer.wrap(bytes));
            }

            FileSender fileSender = new FileSender(new StoreResource(smallFile, null, 16, _fs));

            // when + then
            assertFalse(fileSender.EndOfInput);
            assertEquals(FileChunk.Create(bytes, true), fileSender.ReadChunk(_allocator));
            assertNull(fileSender.ReadChunk(_allocator));
            assertTrue(fileSender.EndOfInput);
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sendLargeFileWithSizeMultipleOfTheChunkSize() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SendLargeFileWithSizeMultipleOfTheChunkSize()
        {
            // given
            sbyte[] bytes = new sbyte[MAX_SIZE * 3];
            _random.NextBytes(bytes);

            File smallFile = TestDirectory.file("smallFile");

            using (StoreChannel storeChannel = _fs.create(smallFile))
            {
                storeChannel.write(ByteBuffer.wrap(bytes));
            }

            FileSender fileSender = new FileSender(new StoreResource(smallFile, null, 16, _fs));

            // when + then
            assertFalse(fileSender.EndOfInput);
            assertEquals(FileChunk.Create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.ReadChunk(_allocator));
            assertEquals(FileChunk.Create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.ReadChunk(_allocator));
            assertEquals(FileChunk.Create(copyOfRange(bytes, MAX_SIZE * 2, bytes.Length), true), fileSender.ReadChunk(_allocator));
            assertNull(fileSender.ReadChunk(_allocator));
            assertTrue(fileSender.EndOfInput);
        }
예제 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public int write(ByteBuffer src) throws java.io.IOException
        public override int Write(ByteBuffer src)
        {
            return(@delegate.write(src));
        }