예제 #1
0
 public DomainPeer(DomainSocket socket)
 {
     this.socket  = socket;
     this.@out    = socket.GetOutputStream();
     this.@in     = socket.GetInputStream();
     this.channel = socket.GetChannel();
 }
예제 #2
0
 public virtual BufferedChannelInput Reset(ReadableByteChannel ch)
 {
     this._channel = ch;
     this._buffer.position(0);
     this._buffer.limit(0);
     return(this);
 }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void handlesDataCrossingBufferBoundaries() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void HandlesDataCrossingBufferBoundaries()
        {
            // Given
            Machine machine = new Machine();

            PackStream.Packer packer = machine.Packer();
            packer.pack(long.MaxValue);
            packer.pack(long.MaxValue);
            packer.Flush();

            ReadableByteChannel ch = Channels.newChannel(new MemoryStream(machine.Output()));

            PackStream.Unpacker unpacker = new PackStream.Unpacker((new BufferedChannelInput(11)).Reset(ch));

            // Serialized ch will look like, and misalign with the 11-byte unpack buffer:

            // [XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX][XX]
            //  mkr \___________data______________/ mkr \___________data______________/
            // \____________unpack buffer_________________/

            // When
            long first  = unpacker.UnpackLong();
            long second = unpacker.UnpackLong();

            // Then
            assertEquals(long.MaxValue, first);
            assertEquals(long.MaxValue, second);
        }
예제 #4
0
        public override void Write(ReadableByteChannel data)
        {
            ByteBuffer intermediate = ByteBuffer.allocate(1000);

            while (true)
            {
                try
                {
                    intermediate.clear();
                    if (data.read(intermediate) == -1)
                    {
                        break;
                    }
                    intermediate.flip();
                    while (intermediate.remaining() > 0)
                    {
                        sbyte value = intermediate.get();
                        assertEquals((_index++) % 10, value);
                    }
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }
        }
예제 #5
0
 public EncryptedPeer(Peer enclosedPeer, IOStreamPair ios)
 {
     this.enclosedPeer = enclosedPeer;
     this.@in          = ios.@in;
     this.@out         = ios.@out;
     this.channel      = ios.@in is ReadableByteChannel ? (ReadableByteChannel)ios.@in : null;
 }
예제 #6
0
        /// <summary>
        /// Append {@code atMost} count of bytes into print stream </summary>
        /// <param name="source"> </param>
        /// <param name="atMost">
        /// @return </param>
        /// <exception cref="IOException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public HexPrinter append(java.nio.channels.ReadableByteChannel source, int atMost) throws java.io.IOException
        public virtual HexPrinter Append(ReadableByteChannel source, int atMost)
        {
            bool       indefinite = atMost == -1;
            ByteBuffer buffer     = ByteBuffer.allocate(4 * 1024);

            while (true)
            {
                buffer.clear();
                if (!indefinite)
                {
                    buffer.limit(Math.Min(buffer.capacity(), atMost));
                }
                int read = source.read(buffer);
                if (read == -1)
                {
                    break;
                }

                atMost -= read;
                buffer.flip();
                while (buffer.hasRemaining())
                {
                    append(buffer.get());
                }
            }
            return(this);
        }
예제 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static char[] readCharArray(java.nio.channels.ReadableByteChannel channel, ByteBuffer buffer, char[] charArray) throws java.io.IOException
        private static char[] ReadCharArray(ReadableByteChannel channel, ByteBuffer buffer, char[] charArray)
        {
            buffer.clear();
            int charsLeft = charArray.Length;
            int maxSize   = buffer.capacity() / 2;
            int offset    = 0;            // offset in chars

            while (charsLeft > 0)
            {
                if (charsLeft > maxSize)
                {
                    buffer.limit(maxSize * 2);
                    charsLeft -= maxSize;
                }
                else
                {
                    buffer.limit(charsLeft * 2);
                    charsLeft = 0;
                }
                if (channel.read(buffer) != buffer.limit())
                {
                    return(null);
                }
                buffer.flip();
                int length = buffer.limit() / 2;
                buffer.asCharBuffer().get(charArray, offset, length);
                offset += length;
                buffer.clear();
            }
            return(charArray);
        }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadALogHeaderFromAByteChannel() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadALogHeaderFromAByteChannel()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
            ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.nio.channels.ReadableByteChannel channel = mock(java.nio.channels.ReadableByteChannel.class);
            ReadableByteChannel channel = mock(typeof(ReadableByteChannel));

            when(channel.read(buffer)).thenAnswer(invocation =>
            {
                buffer.putLong(encodeLogVersion(_expectedLogVersion));
                buffer.putLong(_expectedTxId);
                return(8 + 8);
            });

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LogHeader result = readLogHeader(buffer, channel, true, null);
            LogHeader result = readLogHeader(buffer, channel, true, null);

            // then
            assertEquals(new LogHeader(CURRENT_LOG_VERSION, _expectedLogVersion, _expectedTxId), result);
        }
예제 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long write(String path, java.nio.channels.ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData, int requiredElementAlignment) throws java.io.IOException
        public override long Write(string path, ReadableByteChannel data, ByteBuffer temporaryBuffer, bool hasData, int requiredElementAlignment)
        {
            try
            {
                temporaryBuffer.clear();
                File file = new File(_basePath, path);
                file.ParentFile.mkdirs();

                string fullFilePath = file.ToString();

                _monitor.startReceivingStoreFile(fullFilePath);
                try
                {
                    // We don't add file move actions for these files. The reason is that we will perform the file moves
                    // *after* we have done recovery on the store, and this may delete some files, and add other files.
                    return(WriteDataThroughFileSystem(file, data, temporaryBuffer, hasData));
                }
                finally
                {
                    _monitor.finishReceivingStoreFile(fullFilePath);
                }
            }
            catch (Exception t)
            {
                throw new IOException(t);
            }
        }
예제 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long writeDataThroughFileSystem(java.io.File file, java.nio.channels.ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData) throws java.io.IOException
        private long WriteDataThroughFileSystem(File file, ReadableByteChannel data, ByteBuffer temporaryBuffer, bool hasData)
        {
            using (StoreChannel channel = _fs.create(file))
            {
                return(WriteData(data, temporaryBuffer, hasData, channel));
            }
        }
예제 #11
0
        public override void Write(ReadableByteChannel data)
        {
            ByteBuffer buffer = ByteBuffer.allocate(1000);

            while (true)
            {
                buffer.clear();
                try
                {
                    int size = data.read(buffer);
                    if (size == -1)
                    {
                        break;
                    }
                    if ((_totalSize += size) >= _crashAtSize)
                    {
                        _client.stop();
                        throw new IOException("Fake read error");
                    }
                }
                catch (IOException e)
                {
                    throw new ComException(e);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Reads the header of a log. Data will be read from {@code channel} using supplied {@code buffer}
        /// as to allow more controlled allocation.
        /// </summary>
        /// <param name="buffer"> <seealso cref="ByteBuffer"/> to read into. Passed in to allow control over allocation. </param>
        /// <param name="channel"> <seealso cref="ReadableByteChannel"/> to read from, typically a channel over a file containing the data. </param>
        /// <param name="strict"> if {@code true} then will fail with <seealso cref="IncompleteLogHeaderException"/> on incomplete
        /// header, i.e. if there's not enough data in the channel to even read the header. If {@code false} then
        /// the return value will instead be {@code null}. </param>
        /// <param name="fileForAdditionalErrorInformationOrNull"> when in {@code strict} mode the exception can be
        /// amended with information about which file the channel represents, if any. Purely for better forensics
        /// ability. </param>
        /// <returns> <seealso cref="LogHeader"/> containing the log header data from the {@code channel}. </returns>
        /// <exception cref="IOException"> if unable to read from {@code channel} </exception>
        /// <exception cref="IncompleteLogHeaderException"> if {@code strict} and not enough data could be read </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static LogHeader readLogHeader(ByteBuffer buffer, java.nio.channels.ReadableByteChannel channel, boolean strict, java.io.File fileForAdditionalErrorInformationOrNull) throws java.io.IOException
        public static LogHeader ReadLogHeader(ByteBuffer buffer, ReadableByteChannel channel, bool strict, File fileForAdditionalErrorInformationOrNull)
        {
            buffer.clear();
            buffer.limit(LOG_HEADER_SIZE);

            int read = channel.read(buffer);

            if (read != LOG_HEADER_SIZE)
            {
                if (strict)
                {
                    if (fileForAdditionalErrorInformationOrNull != null)
                    {
                        throw new IncompleteLogHeaderException(fileForAdditionalErrorInformationOrNull, read);
                    }
                    throw new IncompleteLogHeaderException(read);
                }
                return(null);
            }
            buffer.flip();
            long  encodedLogVersions  = buffer.Long;
            sbyte logFormatVersion    = DecodeLogFormatVersion(encodedLogVersions);
            long  logVersion          = DecodeLogVersion(encodedLogVersions);
            long  previousCommittedTx = buffer.Long;

            return(new LogHeader(logFormatVersion, logVersion, previousCommittedTx));
        }
예제 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void close() throws Exception
        public override void Close()
        {
            if (_channel != null)
            {
                _channel.close();
                _channel = null;
            }
        }
예제 #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private System.Nullable<int> tryToReadVersion(java.nio.channels.ReadableByteChannel channel) throws java.io.IOException
        private int?TryToReadVersion(ReadableByteChannel channel)
        {
            sbyte[] array = IoPrimitiveUtils.readBytes(channel, new sbyte[_magic.Length]);
            if (!Arrays.Equals(_magic, array))
            {
                return(null);
            }
            return(array != null?ReadNextInt(channel) : null);
        }
예제 #15
0
 /// <exception cref="System.IO.IOException"/>
 private static void ReadChannelFully(ReadableByteChannel ch, ByteBuffer buf)
 {
     while (buf.Remaining() > 0)
     {
         int n = ch.Read(buf);
         if (n < 0)
         {
             throw new IOException("Premature EOF reading from " + ch);
         }
     }
 }
예제 #16
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public Response<Void> sendDataStream(final java.nio.channels.ReadableByteChannel data)
        public override Response <Void> SendDataStream(ReadableByteChannel data)
        {
            Serializer serializer = buffer =>
            {
                using (BlockLogBuffer writer = new BlockLogBuffer(buffer, (new Monitors()).newMonitor(typeof(ByteCounterMonitor))))
                {
                    writer.Write(data);
                }
            };

            return(SendRequest(MadeUpServer.MadeUpRequestType.SendDataStream, RequestContext, serializer, Protocol.VoidDeserializer));
        }
예제 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static String readLengthAndString(java.nio.channels.ReadableByteChannel channel, ByteBuffer buffer) throws java.io.IOException
        public static string ReadLengthAndString(ReadableByteChannel channel, ByteBuffer buffer)
        {
            int?length = ReadInt(channel, buffer);

            if (length != null)
            {
                char[] chars = new char[length];
                chars = ReadCharArray(channel, buffer, chars);
                return(chars == null ? null : new string( chars ));
            }
            return(null);
        }
예제 #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public int write(java.nio.channels.ReadableByteChannel data) throws java.io.IOException
        public virtual int Write(ReadableByteChannel data)
        {
            int result = 0;
            int bytesRead;

            while ((bytesRead = data.read(_byteBuffer)) >= 0)
            {
                CheckFlush();
                result += bytesRead;
            }
            return(result);
        }
예제 #19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void verifyRecordsInFile(java.nio.channels.ReadableByteChannel channel, int recordCount) throws java.io.IOException
        protected internal virtual void VerifyRecordsInFile(ReadableByteChannel channel, int recordCount)
        {
            ByteBuffer buf         = ByteBuffer.allocate(RecordSize);
            ByteBuffer observation = ByteBuffer.allocate(RecordSize);

            for (int i = 0; i < recordCount; i++)
            {
                GenerateRecordForId(i, buf);
                observation.position(0);
                channel.read(observation);
                AssertRecords(i, observation, buf);
            }
        }
예제 #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public FileChunk readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override FileChunk ReadChunk(ByteBufAllocator allocator)
        {
            if (_state == FINISHED)
            {
                return(null);
            }
            else if (_state == PRE_INIT)
            {
                _channel   = _resource.open();
                _nextBytes = Prefetch();
                if (_nextBytes == null)
                {
                    _state = FINISHED;
                    return(FileChunk.Create(new sbyte[0], true));
                }
                else
                {
                    _state = _nextBytes.Length < MAX_SIZE ? LAST_PENDING : FULL_PENDING;
                }
            }

            if (_state == FULL_PENDING)
            {
                sbyte[] toSend = _nextBytes;
                _nextBytes = Prefetch();
                if (_nextBytes == null)
                {
                    _state = FINISHED;
                    return(FileChunk.Create(toSend, true));
                }
                else if (_nextBytes.Length < MAX_SIZE)
                {
                    _state = LAST_PENDING;
                    return(FileChunk.Create(toSend, false));
                }
                else
                {
                    return(FileChunk.Create(toSend, false));
                }
            }
            else if (_state == LAST_PENDING)
            {
                _state = FINISHED;
                return(FileChunk.Create(_nextBytes, true));
            }
            else
            {
                throw new System.InvalidOperationException();
            }
        }
예제 #21
0
 public override void Write(ReadableByteChannel data)
 {
     try
     {
         using (BlockLogBuffer blockBuffer = new BlockLogBuffer(_target, (new Monitors()).newMonitor(typeof(ByteCounterMonitor))))
         {
             blockBuffer.Write(data);
         }
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
 }
예제 #22
0
        /// <summary>
        /// Trigger store flush (checkpoint) and write <seealso cref="NeoStoreDataSource.listStoreFiles(bool) store files"/> to the
        /// given <seealso cref="StoreWriter"/>.
        /// </summary>
        /// <param name="triggerName"> name of the component asks for store files. </param>
        /// <param name="writer"> store writer to write files to. </param>
        /// <param name="includeLogs"> <code>true</code> if transaction logs should be copied, <code>false</code> otherwise. </param>
        /// <returns> a <seealso cref="RequestContext"/> specifying at which point the store copy started. </returns>
        public virtual RequestContext FlushStoresAndStreamStoreFiles(string triggerName, StoreWriter writer, bool includeLogs)
        {
            try
            {
                string storeCopyIdentifier = Thread.CurrentThread.Name;
                ThrowingAction <IOException> checkPointAction = () =>
                {
                    _monitor.startTryCheckPoint(storeCopyIdentifier);
                    _checkPointer.tryCheckPoint(new SimpleTriggerInfo(triggerName));
                    _monitor.finishTryCheckPoint(storeCopyIdentifier);
                };

                // Copy the store files
                long lastAppliedTransaction;
                StoreCopyCheckPointMutex mutex = _dataSource.StoreCopyCheckPointMutex;
                try
                {
                    using (Resource @lock = mutex.StoreCopy(checkPointAction), ResourceIterator <StoreFileMetadata> files = _dataSource.listStoreFiles(includeLogs))
                    {
                        lastAppliedTransaction = _checkPointer.lastCheckPointedTransactionId();
                        _monitor.startStreamingStoreFiles(storeCopyIdentifier);
                        ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(( int )ByteUnit.mebiBytes(1));
                        while (Files.MoveNext())
                        {
                            StoreFileMetadata meta = Files.Current;
                            File file       = meta.File();
                            bool isLogFile  = meta.LogFile;
                            int  recordSize = meta.RecordSize();

                            using (ReadableByteChannel fileChannel = _fileSystem.open(file, OpenMode.READ))
                            {
                                long fileSize = _fileSystem.getFileSize(file);
                                DoWrite(writer, temporaryBuffer, file, recordSize, fileChannel, fileSize, storeCopyIdentifier, isLogFile);
                            }
                        }
                    }
                }
                finally
                {
                    _monitor.finishStreamingStoreFiles(storeCopyIdentifier);
                }

                return(anonymous(lastAppliedTransaction));
            }
            catch (IOException e)
            {
                throw new ServerFailureException(e);
            }
        }
예제 #23
0
 /// <exception cref="System.IO.IOException"/>
 private static void DoReadFully(ReadableByteChannel ch, InputStream @in, ByteBuffer
                                 buf)
 {
     if (ch != null)
     {
         ReadChannelFully(ch, buf);
     }
     else
     {
         Preconditions.CheckState(!buf.IsDirect(), "Must not use direct buffers with InputStream API"
                                  );
         IOUtils.ReadFully(@in, ((byte[])buf.Array()), buf.ArrayOffset() + buf.Position(),
                           buf.Remaining());
         buf.Position(buf.Position() + buf.Remaining());
     }
 }
예제 #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static boolean readAndFlip(java.nio.channels.ReadableByteChannel channel, ByteBuffer buffer, int bytes) throws java.io.IOException
        public static bool ReadAndFlip(ReadableByteChannel channel, ByteBuffer buffer, int bytes)
        {
            buffer.clear();
            buffer.limit(bytes);
            while (buffer.hasRemaining())
            {
                int read = channel.read(buffer);

                if (read == -1)
                {
                    return(false);
                }
            }
            buffer.flip();
            return(true);
        }
예제 #25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static boolean isEqual(java.io.InputStream stream1, java.io.InputStream stream2) throws java.io.IOException
        private static bool isEqual(Stream stream1, Stream stream2)
        {
            ReadableByteChannel channel1 = Channels.newChannel(stream1);
            ReadableByteChannel channel2 = Channels.newChannel(stream2);

            ByteBuffer buffer1 = ByteBuffer.allocateDirect(1024);
            ByteBuffer buffer2 = ByteBuffer.allocateDirect(1024);

            try
            {
                while (true)
                {
                    int bytesReadFromStream1 = channel1.read(buffer1);
                    int bytesReadFromStream2 = channel2.read(buffer2);

                    if (bytesReadFromStream1 == -1 || bytesReadFromStream2 == -1)
                    {
                        return(bytesReadFromStream1 == bytesReadFromStream2);
                    }

                    buffer1.flip();
                    buffer2.flip();

                    for (int i = 0; i < Math.Min(bytesReadFromStream1, bytesReadFromStream2); i++)
                    {
                        if (buffer1.get() != buffer2.get())
                        {
                            return(false);
                        }
                    }

                    buffer1.compact();
                    buffer2.compact();
                }
            }
            finally
            {
                if (stream1 != null)
                {
                    stream1.Close();
                }
                if (stream2 != null)
                {
                    stream2.Close();
                }
            }
        }
예제 #26
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long write(String path, java.nio.channels.ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData, int requiredElementAlignment) throws java.io.IOException
        public override long Write(string path, ReadableByteChannel data, ByteBuffer temporaryBuffer, bool hasData, int requiredElementAlignment)
        {
            char[] chars = path.ToCharArray();
            _targetBuffer.writeShort(chars.Length);
            Protocol.writeChars(_targetBuffer, chars);
            _targetBuffer.writeByte(hasData ? 1 : 0);
            // TODO Make use of temporaryBuffer?
            BlockLogBuffer buffer       = new BlockLogBuffer(_targetBuffer, _bufferMonitor);
            long           totalWritten = Short.BYTES + chars.Length * Character.BYTES + Byte.BYTES;

            if (hasData)
            {
                _targetBuffer.writeInt(requiredElementAlignment);
                totalWritten += Integer.BYTES;
                totalWritten += buffer.Write(data);
                buffer.Dispose();
            }
            return(totalWritten);
        }
예제 #27
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void fastCopy(java.io.InputStream paramInputStream, java.io.OutputStream paramOutputStream) throws java.io.IOException
        public static void fastCopy(Stream paramInputStream, Stream paramOutputStream)
        {
            ReadableByteChannel readableByteChannel = Channels.newChannel(paramInputStream);
            WritableByteChannel writableByteChannel = Channels.newChannel(paramOutputStream);
            ByteBuffer          byteBuffer          = ByteBuffer.allocateDirect(16384);

            while (readableByteChannel.read(byteBuffer) != -1)
            {
                byteBuffer.flip();
                writableByteChannel.write(byteBuffer);
                byteBuffer.compact();
            }
            byteBuffer.flip();
            while (byteBuffer.hasRemaining())
            {
                writableByteChannel.write(byteBuffer);
            }
            readableByteChannel.close();
            writableByteChannel.close();
        }
예제 #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailWhenUnableToReadALogHeaderFromAChannel() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailWhenUnableToReadALogHeaderFromAChannel()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
            ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.nio.channels.ReadableByteChannel channel = mock(java.nio.channels.ReadableByteChannel.class);
            ReadableByteChannel channel = mock(typeof(ReadableByteChannel));

            when(channel.read(buffer)).thenReturn(1);

            try
            {
                // when
                readLogHeader(buffer, channel, true, null);
                fail("should have thrown");
            }
            catch (IncompleteLogHeaderException)
            {
                // then good
            }
        }
예제 #29
0
 protected internal RemoteBlockReader2(string file, string bpid, long blockId, DataChecksum
                                       checksum, bool verifyChecksum, long startOffset, long firstChunkOffset, long bytesToRead
                                       , Peer peer, DatanodeID datanodeID, PeerCache peerCache)
 {
     this.isLocal = DFSClient.IsLocalAddress(NetUtils.CreateSocketAddr(datanodeID.GetXferAddr
                                                                           ()));
     // Path is used only for printing block and file information in debug
     this.peer           = peer;
     this.datanodeID     = datanodeID;
     this.@in            = peer.GetInputStreamChannel();
     this.checksum       = checksum;
     this.verifyChecksum = verifyChecksum;
     this.startOffset    = Math.Max(startOffset, 0);
     this.filename       = file;
     this.peerCache      = peerCache;
     this.blockId        = blockId;
     // The total number of bytes that we need to transfer from the DN is
     // the amount that the user wants (bytesToRead), plus the padding at
     // the beginning in order to chunk-align. Note that the DN may elect
     // to send more than this amount if the read starts/ends mid-chunk.
     this.bytesNeededToFinish = bytesToRead + (startOffset - firstChunkOffset);
     bytesPerChecksum         = this.checksum.GetBytesPerChecksum();
     checksumSize             = this.checksum.GetChecksumSize();
 }
예제 #30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long writeData(java.nio.channels.ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData, java.nio.channels.WritableByteChannel channel) throws java.io.IOException
        private long WriteData(ReadableByteChannel data, ByteBuffer temporaryBuffer, bool hasData, WritableByteChannel channel)
        {
            long totalToWrite = 0;
            long totalWritten = 0;

            if (hasData)
            {
                while (data.read(temporaryBuffer) >= 0)
                {
                    temporaryBuffer.flip();
                    totalToWrite += temporaryBuffer.limit();
                    int bytesWritten;
                    while ((totalWritten += bytesWritten = channel.write(temporaryBuffer)) < totalToWrite)
                    {
                        if (bytesWritten < 0)
                        {
                            throw new IOException("Unable to write to disk, reported bytes written was " + bytesWritten);
                        }
                    }
                    temporaryBuffer.clear();
                }
            }
            return(totalWritten);
        }
예제 #31
0
 public static Reader newReader(ReadableByteChannel arg0, String arg1)
 {
     return Static.CallMethod<Reader>(typeof(Channels), "newReader", "(Ljava/nio/channels/ReadableByteChannel;Ljava/lang/String;)Ljava/io/Reader;", arg0, arg1);
 }
예제 #32
0
 public static Reader newReader(ReadableByteChannel arg0, CharsetDecoder arg1, int arg2)
 {
     return Static.CallMethod<Reader>(typeof(Channels), "newReader", "(Ljava/nio/channels/ReadableByteChannel;Ljava/nio/charset/CharsetDecoder;I)Ljava/io/Reader;", arg0, arg1, arg2);
 }
예제 #33
0
 public static InputStream newInputStream(ReadableByteChannel arg0)
 {
     return Static.CallMethod<InputStream>(typeof(Channels), "newInputStream", "(Ljava/nio/channels/ReadableByteChannel;)Ljava/io/InputStream;", arg0);
 }