| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (1.8.0_151-google-v7) on Tue Oct 02 14:37:32 PDT 2018 --> |
| <title>FileBasedSource.FileBasedReader (Apache Beam 2.7.0-SNAPSHOT)</title> |
| <meta name="date" content="2018-10-02"> |
| <link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../../../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="FileBasedSource.FileBasedReader (Apache Beam 2.7.0-SNAPSHOT)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":6,"i5":10,"i6":6}; |
| var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]}; |
| var altColor = "altColor"; |
| var rowColor = "rowColor"; |
| var tableTab = "tableTab"; |
| var activeTableTab = "activeTableTab"; |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.Mode.html" title="enum in org.apache.beam.sdk.io"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" target="_top">Frames</a></li> |
| <li><a href="FileBasedSource.FileBasedReader.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li><a href="#fields.inherited.from.class.org.apache.beam.sdk.io.BoundedSource.BoundedReader">Field</a> | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">org.apache.beam.sdk.io</div> |
| <h2 title="Class FileBasedSource.FileBasedReader" class="title">Class FileBasedSource.FileBasedReader<T></h2> |
| </div> |
| <div class="contentContainer"> |
| <ul class="inheritance"> |
| <li>java.lang.Object</li> |
| <li> |
| <ul class="inheritance"> |
| <li><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io">org.apache.beam.sdk.io.Source.Reader</a><T></li> |
| <li> |
| <ul class="inheritance"> |
| <li><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io">org.apache.beam.sdk.io.BoundedSource.BoundedReader</a><T></li> |
| <li> |
| <ul class="inheritance"> |
| <li><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">org.apache.beam.sdk.io.OffsetBasedSource.OffsetBasedReader</a><T></li> |
| <li> |
| <ul class="inheritance"> |
| <li>org.apache.beam.sdk.io.FileBasedSource.FileBasedReader<T></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <dl> |
| <dt>All Implemented Interfaces:</dt> |
| <dd>java.lang.AutoCloseable</dd> |
| </dl> |
| <dl> |
| <dt>Direct Known Subclasses:</dt> |
| <dd><a href="../../../../../org/apache/beam/sdk/io/BlockBasedSource.BlockBasedReader.html" title="class in org.apache.beam.sdk.io">BlockBasedSource.BlockBasedReader</a>, <a href="../../../../../org/apache/beam/sdk/io/CompressedSource.CompressedReader.html" title="class in org.apache.beam.sdk.io">CompressedSource.CompressedReader</a></dd> |
| </dl> |
| <dl> |
| <dt>Enclosing class:</dt> |
| <dd><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io">FileBasedSource</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="type parameter in FileBasedSource">T</a>></dd> |
| </dl> |
| <hr> |
| <br> |
| <pre>public abstract static class <span class="typeNameLabel">FileBasedSource.FileBasedReader<T></span> |
| extends <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a><T></pre> |
| <div class="block">A <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io"><code>reader</code></a> that implements code common to readers of <code>FileBasedSource</code>s. |
| |
| <h2>Seekability</h2> |
| |
| <p>This reader uses a <code>ReadableByteChannel</code> created for the file represented by the |
| corresponding source to efficiently move to the correct starting position defined in the |
| source. Subclasses of this reader should implement <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startReading-java.nio.channels.ReadableByteChannel-"><code>startReading(java.nio.channels.ReadableByteChannel)</code></a> to get access to this |
| channel. If the source corresponding to the reader is for a subrange of a file the <code>ReadableByteChannel</code> provided is guaranteed to be an instance of the type <code>SeekableByteChannel</code>, which may be used by subclass to traverse back in the channel to |
| determine the correct starting position. |
| |
| <h2>Reading Records</h2> |
| |
| <p>Sequential reading is implemented using <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#readNextRecord--"><code>readNextRecord()</code></a>. |
| |
| <p>Then <code>FileBasedReader</code> implements "reading a range [A, B)" in the following way. |
| |
| <ol> |
| <li><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#start--"><code>OffsetBasedSource.OffsetBasedReader.start()</code></a> opens the file |
| <li><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#start--"><code>OffsetBasedSource.OffsetBasedReader.start()</code></a> seeks the <code>SeekableByteChannel</code> to A (reading offset ranges for |
| non-seekable files is not supported) and calls <code>startReading()</code> |
| <li><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#start--"><code>OffsetBasedSource.OffsetBasedReader.start()</code></a> calls <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#advance--"><code>OffsetBasedSource.OffsetBasedReader.advance()</code></a> once, which, via <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#readNextRecord--"><code>readNextRecord()</code></a>, locates |
| the first record which is at a split point AND its offset is at or after A. If this |
| record is at or after B, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#advance--"><code>OffsetBasedSource.OffsetBasedReader.advance()</code></a> returns false and reading is finished. |
| <li>if the previous advance call returned <code>true</code> sequential reading starts and <code>advance()</code> will be called repeatedly |
| </ol> |
| |
| <code>advance()</code> calls <code>readNextRecord()</code> on the subclass, and stops (returns false) if |
| the new record is at a split point AND the offset of the new record is at or after B. |
| |
| <h2>Thread Safety</h2> |
| |
| <p>Since this class implements <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io"><code>Source.Reader</code></a> it guarantees thread safety. Abstract |
| methods defined here will not be accessed by more than one thread concurrently.</div> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- =========== FIELD SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="field.summary"> |
| <!-- --> |
| </a> |
| <h3>Field Summary</h3> |
| <ul class="blockList"> |
| <li class="blockList"><a name="fields.inherited.from.class.org.apache.beam.sdk.io.BoundedSource.BoundedReader"> |
| <!-- --> |
| </a> |
| <h3>Fields inherited from class org.apache.beam.sdk.io.<a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io">BoundedSource.BoundedReader</a></h3> |
| <code><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#SPLIT_POINTS_UNKNOWN">SPLIT_POINTS_UNKNOWN</a></code></li> |
| </ul> |
| </li> |
| </ul> |
| <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.summary"> |
| <!-- --> |
| </a> |
| <h3>Constructor Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> |
| <caption><span>Constructors</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colOne" scope="col">Constructor and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colOne"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#FileBasedReader-org.apache.beam.sdk.io.FileBasedSource-">FileBasedReader</a></span>(<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io">FileBasedSource</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>> source)</code> |
| <div class="block">Subclasses should not perform IO operations at the constructor.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| <!-- ========== METHOD SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.summary"> |
| <!-- --> |
| </a> |
| <h3>Method Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> |
| <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Method and Description</th> |
| </tr> |
| <tr id="i0" class="altColor"> |
| <td class="colFirst"><code>protected boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#advanceImpl--">advanceImpl</a></span>()</code> |
| <div class="block">Advances to the next record and returns <code>true</code>, or returns false if there is no next |
| record.</div> |
| </td> |
| </tr> |
| <tr id="i1" class="rowColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#allowsDynamicSplitting--">allowsDynamicSplitting</a></span>()</code> |
| <div class="block">Whether this reader should allow dynamic splitting of the offset ranges.</div> |
| </td> |
| </tr> |
| <tr id="i2" class="altColor"> |
| <td class="colFirst"><code>void</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#close--">close</a></span>()</code> |
| <div class="block">Closes any <code>ReadableByteChannel</code> created for the current reader.</div> |
| </td> |
| </tr> |
| <tr id="i3" class="rowColor"> |
| <td class="colFirst"><code><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io">FileBasedSource</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#getCurrentSource--">getCurrentSource</a></span>()</code> |
| <div class="block">Returns a <code>Source</code> describing the same input that this <code>Reader</code> currently reads |
| (including items already read).</div> |
| </td> |
| </tr> |
| <tr id="i4" class="altColor"> |
| <td class="colFirst"><code>protected abstract boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#readNextRecord--">readNextRecord</a></span>()</code> |
| <div class="block">Reads the next record from the channel provided by <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startReading-java.nio.channels.ReadableByteChannel-"><code>startReading(java.nio.channels.ReadableByteChannel)</code></a>.</div> |
| </td> |
| </tr> |
| <tr id="i5" class="rowColor"> |
| <td class="colFirst"><code>protected boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startImpl--">startImpl</a></span>()</code> |
| <div class="block">Initializes the <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io"><code>OffsetBasedSource.OffsetBasedReader</code></a> and advances to the first record, |
| returning <code>true</code> if there is a record available to be read.</div> |
| </td> |
| </tr> |
| <tr id="i6" class="altColor"> |
| <td class="colFirst"><code>protected abstract void</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startReading-java.nio.channels.ReadableByteChannel-">startReading</a></span>(java.nio.channels.ReadableByteChannel channel)</code> |
| <div class="block">Performs any initialization of the subclass of <code>FileBasedReader</code> that involves IO |
| operations.</div> |
| </td> |
| </tr> |
| </table> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.org.apache.beam.sdk.io.OffsetBasedSource.OffsetBasedReader"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class org.apache.beam.sdk.io.<a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a></h3> |
| <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#advance--">advance</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getCurrentOffset--">getCurrentOffset</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getFractionConsumed--">getFractionConsumed</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getSplitPointsConsumed--">getSplitPointsConsumed</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getSplitPointsRemaining--">getSplitPointsRemaining</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#isAtSplitPoint--">isAtSplitPoint</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#isDone--">isDone</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#isStarted--">isStarted</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#splitAtFraction-double-">splitAtFraction</a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#start--">start</a></code></li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.org.apache.beam.sdk.io.BoundedSource.BoundedReader"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class org.apache.beam.sdk.io.<a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io">BoundedSource.BoundedReader</a></h3> |
| <code><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#getCurrentTimestamp--">getCurrentTimestamp</a></code></li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.org.apache.beam.sdk.io.Source.Reader"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class org.apache.beam.sdk.io.<a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io">Source.Reader</a></h3> |
| <code><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrent--">getCurrent</a></code></li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object"> |
| <!-- --> |
| </a> |
| <h3>Methods inherited from class java.lang.Object</h3> |
| <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ========= CONSTRUCTOR DETAIL ======== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="constructor.detail"> |
| <!-- --> |
| </a> |
| <h3>Constructor Detail</h3> |
| <a name="FileBasedReader-org.apache.beam.sdk.io.FileBasedSource-"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>FileBasedReader</h4> |
| <pre>public FileBasedReader(<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io">FileBasedSource</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>> source)</pre> |
| <div class="block">Subclasses should not perform IO operations at the constructor. All IO operations should be |
| delayed until the <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startReading-java.nio.channels.ReadableByteChannel-"><code>startReading(java.nio.channels.ReadableByteChannel)</code></a> method is invoked.</div> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <!-- ============ METHOD DETAIL ========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="method.detail"> |
| <!-- --> |
| </a> |
| <h3>Method Detail</h3> |
| <a name="getCurrentSource--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>getCurrentSource</h4> |
| <pre>public <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io">FileBasedSource</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>> getCurrentSource()</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from class: <code><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#getCurrentSource--">BoundedSource.BoundedReader</a></code></span></div> |
| <div class="block">Returns a <code>Source</code> describing the same input that this <code>Reader</code> currently reads |
| (including items already read). |
| |
| <h3>Usage</h3> |
| |
| <p>Reader subclasses can use this method for convenience to access unchanging properties of |
| the source being read. Alternatively, they can cache these properties in the constructor. |
| |
| <p>The framework will call this method in the course of dynamic work rebalancing, e.g. after |
| a successful <a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#splitAtFraction-double-"><code>BoundedSource.BoundedReader.splitAtFraction(double)</code></a> call. |
| |
| <h3>Mutability and thread safety</h3> |
| |
| <p>Remember that <a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><code>Source</code></a> objects must always be immutable. However, the return value |
| of this function may be affected by dynamic work rebalancing, happening asynchronously via |
| <a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#splitAtFraction-double-"><code>BoundedSource.BoundedReader.splitAtFraction(double)</code></a>, meaning it can return a different <a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><code>Source</code></a> object. However, the returned object itself will still itself be immutable. Callers |
| must take care not to rely on properties of the returned source that may be asynchronously |
| changed as a result of this process (e.g. do not cache an end offset when reading a file). |
| |
| <h3>Implementation</h3> |
| |
| <p>For convenience, subclasses should usually return the most concrete subclass of <a href="../../../../../org/apache/beam/sdk/io/Source.html" title="class in org.apache.beam.sdk.io"><code>Source</code></a> possible. In practice, the implementation of this method should nearly always be one |
| of the following: |
| |
| <ul> |
| <li>Source that inherits from a base class that already implements <a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html#getCurrentSource--"><code>BoundedSource.BoundedReader.getCurrentSource()</code></a>: delegate to base class. In this case, it is almost always an error |
| for the subclass to maintain its own copy of the source. |
| <pre><code> |
| public FooReader(FooSource<T> source) { |
| super(source); |
| } |
| |
| public FooSource<T> getCurrentSource() { |
| return (FooSource<T>)super.getCurrentSource(); |
| } |
| </code></pre> |
| <li>Source that does not support dynamic work rebalancing: return a private final variable. |
| <pre><code> |
| private final FooSource<T> source; |
| |
| public FooReader(FooSource<T> source) { |
| this.source = source; |
| } |
| |
| public FooSource<T> getCurrentSource() { |
| return source; |
| } |
| </code></pre> |
| <li><a href="../../../../../org/apache/beam/sdk/io/BoundedSource.BoundedReader.html" title="class in org.apache.beam.sdk.io"><code>BoundedSource.BoundedReader</code></a> that explicitly supports dynamic work rebalancing: |
| maintain a variable pointing to an immutable source object, and protect it with |
| synchronization. |
| <pre><code> |
| private FooSource<T> source; |
| |
| public FooReader(FooSource<T> source) { |
| this.source = source; |
| } |
| |
| public synchronized FooSource<T> getCurrentSource() { |
| return source; |
| } |
| |
| public synchronized FooSource<T> splitAtFraction(double fraction) { |
| ... |
| FooSource<T> primary = ...; |
| FooSource<T> residual = ...; |
| this.source = primary; |
| return residual; |
| } |
| </code></pre> |
| </ul></div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Overrides:</span></dt> |
| <dd><code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getCurrentSource--">getCurrentSource</a></code> in class <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="startImpl--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>startImpl</h4> |
| <pre>protected final boolean startImpl() |
| throws java.io.IOException</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from class: <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#startImpl--">OffsetBasedSource.OffsetBasedReader</a></code></span></div> |
| <div class="block">Initializes the <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io"><code>OffsetBasedSource.OffsetBasedReader</code></a> and advances to the first record, |
| returning <code>true</code> if there is a record available to be read. This method will be invoked |
| exactly once and may perform expensive setup operations that are needed to initialize the |
| reader. |
| |
| <p>This function is the <code>OffsetBasedReader</code> implementation of <code>BoundedReader#start</code>. The key difference is that the implementor can ignore the possibility |
| that it should no longer produce the first record, either because it has exceeded the |
| original <code>endOffset</code> assigned to the reader, or because a concurrent call to <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#splitAtFraction-double-"><code>OffsetBasedSource.OffsetBasedReader.splitAtFraction(double)</code></a> has changed the source to shrink the offset range being read.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#startImpl--">startImpl</a></code> in class <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></dd> |
| <dt><span class="throwsLabel">Throws:</span></dt> |
| <dd><code>java.io.IOException</code></dd> |
| <dt><span class="seeLabel">See Also:</span></dt> |
| <dd><code>BoundedReader#start</code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="advanceImpl--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>advanceImpl</h4> |
| <pre>protected final boolean advanceImpl() |
| throws java.io.IOException</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from class: <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#advanceImpl--">OffsetBasedSource.OffsetBasedReader</a></code></span></div> |
| <div class="block">Advances to the next record and returns <code>true</code>, or returns false if there is no next |
| record. |
| |
| <p>This function is the <code>OffsetBasedReader</code> implementation of <code>BoundedReader#advance</code>. The key difference is that the implementor can ignore the possibility |
| that it should no longer produce the next record, either because it has exceeded the original |
| <code>endOffset</code> assigned to the reader, or because a concurrent call to <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#splitAtFraction-double-"><code>OffsetBasedSource.OffsetBasedReader.splitAtFraction(double)</code></a> has changed the source to shrink the offset range being read.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#advanceImpl--">advanceImpl</a></code> in class <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></dd> |
| <dt><span class="throwsLabel">Throws:</span></dt> |
| <dd><code>java.io.IOException</code></dd> |
| <dt><span class="seeLabel">See Also:</span></dt> |
| <dd><code>BoundedReader#advance</code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="close--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>close</h4> |
| <pre>public void close() |
| throws java.io.IOException</pre> |
| <div class="block">Closes any <code>ReadableByteChannel</code> created for the current reader. This implementation is |
| idempotent. Any <code>close()</code> method introduced by a subclass must be idempotent and must |
| call the <code>close()</code> method in the <code>FileBasedReader</code>.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code>close</code> in interface <code>java.lang.AutoCloseable</code></dd> |
| <dt><span class="overrideSpecifyLabel">Specified by:</span></dt> |
| <dd><code><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#close--">close</a></code> in class <code><a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html" title="class in org.apache.beam.sdk.io">Source.Reader</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></dd> |
| <dt><span class="throwsLabel">Throws:</span></dt> |
| <dd><code>java.io.IOException</code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="allowsDynamicSplitting--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>allowsDynamicSplitting</h4> |
| <pre>public boolean allowsDynamicSplitting()</pre> |
| <div class="block"><span class="descfrmTypeLabel">Description copied from class: <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#allowsDynamicSplitting--">OffsetBasedSource.OffsetBasedReader</a></code></span></div> |
| <div class="block">Whether this reader should allow dynamic splitting of the offset ranges. |
| |
| <p>True by default. Override this to return false if the reader cannot support dynamic |
| splitting correctly. If this returns false, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#splitAtFraction-double-"><code>OffsetBasedSource.OffsetBasedReader.splitAtFraction(double)</code></a> will |
| refuse all split requests.</div> |
| <dl> |
| <dt><span class="overrideSpecifyLabel">Overrides:</span></dt> |
| <dd><code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#allowsDynamicSplitting--">allowsDynamicSplitting</a></code> in class <code><a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html" title="class in org.apache.beam.sdk.io">OffsetBasedSource.OffsetBasedReader</a><<a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" title="type parameter in FileBasedSource.FileBasedReader">T</a>></code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="startReading-java.nio.channels.ReadableByteChannel-"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>startReading</h4> |
| <pre>protected abstract void startReading(java.nio.channels.ReadableByteChannel channel) |
| throws java.io.IOException</pre> |
| <div class="block">Performs any initialization of the subclass of <code>FileBasedReader</code> that involves IO |
| operations. Will only be invoked once and before that invocation the base class will seek the |
| channel to the source's starting offset. |
| |
| <p>Provided <code>ReadableByteChannel</code> is for the file represented by the source of this |
| reader. Subclass may use the <code>channel</code> to build a higher level IO abstraction, e.g., a |
| BufferedReader or an XML parser. |
| |
| <p>If the corresponding source is for a subrange of a file, <code>channel</code> is guaranteed to |
| be an instance of the type <code>SeekableByteChannel</code>. |
| |
| <p>After this method is invoked the base class will not be reading data from the channel or |
| adjusting the position of the channel. But the base class is responsible for properly closing |
| the channel.</div> |
| <dl> |
| <dt><span class="paramLabel">Parameters:</span></dt> |
| <dd><code>channel</code> - a byte channel representing the file backing the reader.</dd> |
| <dt><span class="throwsLabel">Throws:</span></dt> |
| <dd><code>java.io.IOException</code></dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="readNextRecord--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>readNextRecord</h4> |
| <pre>protected abstract boolean readNextRecord() |
| throws java.io.IOException</pre> |
| <div class="block">Reads the next record from the channel provided by <a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html#startReading-java.nio.channels.ReadableByteChannel-"><code>startReading(java.nio.channels.ReadableByteChannel)</code></a>. Methods <a href="../../../../../org/apache/beam/sdk/io/Source.Reader.html#getCurrent--"><code>Source.Reader.getCurrent()</code></a>, <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#getCurrentOffset--"><code>OffsetBasedSource.OffsetBasedReader.getCurrentOffset()</code></a>, and <a href="../../../../../org/apache/beam/sdk/io/OffsetBasedSource.OffsetBasedReader.html#isAtSplitPoint--"><code>OffsetBasedSource.OffsetBasedReader.isAtSplitPoint()</code></a> should return the |
| corresponding information about the record read by the last invocation of this method. |
| |
| <p>Note that this method will be called the same way for reading the first record in the |
| source (file or offset range in the file) and for reading subsequent records. It is up to the |
| subclass to do anything special for locating and reading the first record, if necessary.</div> |
| <dl> |
| <dt><span class="returnLabel">Returns:</span></dt> |
| <dd><code>true</code> if a record was successfully read, <code>false</code> if the end of the |
| channel was reached before successfully reading a new record.</dd> |
| <dt><span class="throwsLabel">Throws:</span></dt> |
| <dd><code>java.io.IOException</code></dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.html" title="class in org.apache.beam.sdk.io"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../../../../org/apache/beam/sdk/io/FileBasedSource.Mode.html" title="enum in org.apache.beam.sdk.io"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../../index.html?org/apache/beam/sdk/io/FileBasedSource.FileBasedReader.html" target="_top">Frames</a></li> |
| <li><a href="FileBasedSource.FileBasedReader.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Nested | </li> |
| <li><a href="#fields.inherited.from.class.org.apache.beam.sdk.io.BoundedSource.BoundedReader">Field</a> | </li> |
| <li><a href="#constructor.summary">Constr</a> | </li> |
| <li><a href="#method.summary">Method</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#constructor.detail">Constr</a> | </li> |
| <li><a href="#method.detail">Method</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |