//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public SectionedCharBuffer read(SectionedCharBuffer buffer, int from) throws java.io.IOException public override SectionedCharBuffer Read(SectionedCharBuffer buffer, int from) { while (true) { _current.read(buffer, from); if (buffer.HasAvailable()) { // OK we read something from the current reader CheckNewLineRequirement(buffer.Array(), buffer.Front() - 1); return(buffer); } // Even if there's no line-ending at the end of this source we should introduce one // otherwise the last line of this source and the first line of the next source will // look like one long line. if (_requiresNewLine) { buffer.Append('\n'); _requiresNewLine = false; return(buffer); } if (!GoToNextSource()) { break; } from = buffer.Pivot(); } return(buffer); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldTrackAbsolutePosition() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldTrackAbsolutePosition() { // GIVEN string[][] data = new string[][] { new string[] { "this is", "the first line" }, new string[] { "where this", "is the second line" } }; RawIterator <CharReadable, IOException> readers = ReaderIteratorFromStrings(data, '\n'); CharReadable reader = new MultiReadable(readers); assertEquals(0L, reader.Position()); SectionedCharBuffer buffer = new SectionedCharBuffer(15); // WHEN reader.Read(buffer, buffer.Front()); assertEquals(15, reader.Position()); reader.Read(buffer, buffer.Front()); assertEquals(23, reader.Position(), "Should not transition to a new reader in the middle of a read"); assertEquals("Reader1", reader.SourceDescription()); // we will transition to the new reader in the call below reader.Read(buffer, buffer.Front()); assertEquals(23 + 15, reader.Position()); reader.Read(buffer, buffer.Front()); assertEquals(23 + 30, reader.Position()); reader.Read(buffer, buffer.Front()); assertFalse(buffer.HasAvailable()); }
/// <summary> /// Copies characters in the <seealso cref="array()"/> from (and including) the given {@code from} index of the array /// and all characters forwards to <seealso cref="front()"/> (excluding) index. These characters are copied into /// the <seealso cref="array()"/> of the given {@code into} buffer, where the character {@code array[from]} will /// be be copied to {@code into.array[pivot-(front-from)]}, and so on. As an example: /// /// <pre> /// pivot (i.e. effective buffer size) = 16 /// buffer A /// <------ back ------> <------ front -----> /// [ . . . |abcd.efgh.ijkl.mnop] /// ^ = 25 /// /// A.compactInto( B, 25 ) /// /// buffer B /// <------ back ------> <------ front -----> /// [ . . jkl.mnop| . . . ] /// </pre> /// </summary> /// <param name="into"> which buffer to compact into. </param> /// <param name="from"> the array index to start compacting from. </param> public virtual void Compact(SectionedCharBuffer into, int from) { Debug.Assert(_buffer.Length == into._buffer.Length); int diff = _front - from; into._back = _pivot - diff; Array.Copy(_buffer, from, into._buffer, into._back, diff); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public SectionedCharBuffer read(SectionedCharBuffer buffer, int from) throws java.io.IOException public override SectionedCharBuffer Read(SectionedCharBuffer buffer, int from) { try { return(RegisterBytesRead(Actual.read(buffer, from))); } finally { ReadsCompleted++; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Parameters public static java.util.Collection<ReadMethod> readMethods() public static ICollection <ReadMethod> ReadMethods() { return(Arrays.asList((readable, length) => { SectionedCharBuffer readText = new SectionedCharBuffer(length); readable.read(readText, readText.Front()); return copyOfRange(readText.Array(), readText.Pivot(), readText.Front()); }, (readable, length) => { char[] result = new char[length]; readable.read(result, 0, length); return result; })); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldHandleReadAheadEmptyData() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldHandleReadAheadEmptyData() { // GIVEN TrackingReader actual = new TrackingReader(0); int bufferSize = 10; CharReadable aheadReadable = ThreadAheadReadable.ThreadAhead(actual, bufferSize); // WHEN actual.AwaitCompletedReadAttempts(1); // THEN SectionedCharBuffer buffer = new SectionedCharBuffer(bufferSize); buffer = aheadReadable.Read(buffer, buffer.Front()); assertEquals(buffer.Pivot(), buffer.Back()); assertEquals(buffer.Pivot(), buffer.Front()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldReadAhead() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldReadAhead() { // GIVEN TrackingReader actual = new TrackingReader(23); int bufferSize = 5; CharReadable aheadReader = ThreadAheadReadable.ThreadAhead(actual, bufferSize); SectionedCharBuffer buffer = new SectionedCharBuffer(bufferSize); // WHEN starting it up it should read and fill the buffer to the brim assertEquals(bufferSize, actual.AwaitCompletedReadAttempts(1)); // WHEN we read one buffer int read = 0; buffer = aheadReader.Read(buffer, buffer.Front()); AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize); read += buffer.Available(); // and simulate reading all characters, i.e. back section will be empty in the new buffer buffer = aheadReader.Read(buffer, buffer.Front()); AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize); read += buffer.Available(); // then simulate reading some characters, i.e. back section will contain some characters int keep = 2; buffer = aheadReader.Read(buffer, buffer.Front() - keep); AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize); read += buffer.Available(); keep = 3; buffer = aheadReader.Read(buffer, buffer.Front() - keep); AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize); read += buffer.Available(); keep = 1; buffer = aheadReader.Read(buffer, buffer.Front() - keep); assertEquals(3, buffer.Available()); AssertBuffer(Chars(read - keep, buffer.Available() + keep), buffer, keep, 3); read += buffer.Available(); assertEquals(23, read); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void shouldComplyWithSpecifiedCharset(java.nio.charset.Charset charset) throws Exception private void ShouldComplyWithSpecifiedCharset(Charset charset) { // GIVEN string data = "abcåäö[]{}"; File file = WriteToFile(data, charset); // WHEN CharReadable reader = Readables.Files(charset, file); SectionedCharBuffer buffer = new SectionedCharBuffer(100); buffer = reader.Read(buffer, buffer.Front()); // THEN char[] expected = data.ToCharArray(); char[] array = buffer.Array(); assertEquals(expected.Length, buffer.Available()); for (int i = 0; i < expected.Length; i++) { assertEquals(expected[i], array[buffer.Pivot() + i]); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTrackPosition() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTrackPosition() { // GIVEN string data = "1234567890"; // ^ ^ CharReadable reader = Readables.Wrap(data); SectionedCharBuffer buffer = new SectionedCharBuffer(4); // WHEN int expected = 0; do { buffer = reader.Read(buffer, buffer.Front()); expected += buffer.Available(); // THEN assertEquals(expected, reader.Position()); } while (buffer.HasAvailable()); // and THEN assertEquals(data.ToCharArray().length, expected); }
internal virtual SectionedCharBuffer RegisterBytesRead(SectionedCharBuffer buffer) { BytesRead += buffer.Available(); return(buffer); }
private static void AssertBuffer(char[] expectedChars, SectionedCharBuffer buffer, int charsInBack, int charsInFront) { assertEquals(buffer.Pivot() - charsInBack, buffer.Back()); assertEquals(buffer.Pivot() + charsInFront, buffer.Front()); assertArrayEquals(expectedChars, copyOfRange(buffer.Array(), buffer.Back(), buffer.Front())); }
public override SectionedCharBuffer read(SectionedCharBuffer buffer, int from) { return(buffer); }