<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi, Bertrand,<div><br></div><div>KarmaFileChunk is not similar to Netty's ChunkedFile. &nbsp;I probably should have named it KarmaChunk and may change it to that. &nbsp;</div><div><br></div><div>Rather KarmaFileChunk is similar to the use of a ChannelBuffer in Netty's ChunkedFile and ChunkedNioStream. &nbsp;In Netty the data is held in the ChannelBuffer and is not instrumented. &nbsp;As you can see, the KarmaFileChunk is highly instrumented. &nbsp;The reason for this is that we want to be able to use the KarmaFileChunk for situations where delivery is independent of the original sender's connections with receivers. &nbsp;So, as a result, we have to keep track of what has been transferred prior to a connection being broken. &nbsp;</div><div><br></div><div>We do have plans to open source the project of which KarmaFileChunk is a part. &nbsp;Those plans have not been finalized and are in concert with IEEE standards.</div><div><br></div><div>I hope this helps you. &nbsp;If you look at the KarmaDecoder, the rest of the application can easily be inferred. &nbsp;Essentially the sender uses ChannelFutures in conjunction with Object monitors to make sure that certain parts of multiple objects sent are sent in a particular order. &nbsp;Thus, for KarmaDecoder, we make sure that a KarmaManager with the same UUID as KarmaFileChunks precedes the sending of the chunks, and this can include any number of files as well as any number of file chunks.</div><div><br></div><div>I prefer streaming of files to the random access approach.</div><div><br></div><div>Mike</div><div><br></div><div><br><div><div>On Sep 14, 2009, at 11:35 AM, Bertrand Goetzmann wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello Michael,<div><br></div><div>Is KarmaFileChunk similar to Netty's ChunkedFile?</div><div>Is it Karma is an open source project based on Netty? Where can I find description, example, and so on, on Karma?</div><div> <br></div><div>Thank you for your help.</div><div><br></div><div>Bertrand.<br><br><div class="gmail_quote">2009/9/14 Michael McGrady <span dir="ltr">&lt;<a href="mailto:mmcgrady@topiatechnology.com">mmcgrady@topiatechnology.com</a>&gt;</span><br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word">I was going to say that this is what KarmaDecoder does. &nbsp;Here is the basic data object used in KarmaDecoder.<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <font face="Helvetica"><span style="font-size:medium"><font face="Monaco" size="3"><span style="font-size:11px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> /**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@author</span><span style="color:#000000"> </span><span style="text-decoration:underline">Mike</span><span style="color:#000000"> </span>McGrady</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@version</span><span style="color:#000000"> </span><span style="text-decoration:underline">Karma</span><span style="color:#000000"> </span>Alpha<span style="color:#000000"> </span>v001</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 127, 159)"><span style="color:#000000">&nbsp;</span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span><span style="color:#7f9fbf">@param</span><span style="color:#000000"> </span>&lt;KarmaFileChunk&gt;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@since</span><span style="color:#000000"> </span>August<span style="color:#000000"> </span>2009.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*/</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="color:#7f0055">public</span> <span style="color:#7f0055">final</span> <span style="color:#7f0055">class</span> KarmaFileChunk <span style="color:#7f0055">implements</span> Serializable,</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>Comparable&lt;KarmaFileChunk&gt; {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*</span>&nbsp;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">private</span> <span style="color:#7f0055">static</span> <span style="color:#7f0055">final</span> <span style="color:#7f0055">long</span> <span style="color:#0000c0">serialVersionUID</span> = -8062599394269438322L;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>last<span style="color:#000000"> </span>chunk<span style="color:#000000"> </span>of<span style="color:#000000"> </span>a<span style="color:#000000"> </span>file.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>boolean<span style="color:#000000"> </span><span style="color:#0000c0">isLast</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>ID<span style="color:#000000"> </span>of<span style="color:#000000"> </span>the<span style="color:#000000"> </span>associated<span style="color:#000000"> </span>KarmaManager.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> UUID </span><span style="color:#0000c0">uuid</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>bytes<span style="color:#000000"> </span>of<span style="color:#000000"> </span>the<span style="color:#000000"> </span>chunk.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>byte<span style="color:#000000">[] </span><span style="color:#0000c0">bytes</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>sequential<span style="color:#000000"> </span>ID<span style="color:#000000"> </span>of<span style="color:#000000"> </span>the<span style="color:#000000"> </span>chunk<span style="color:#000000"> </span>beginning<span style="color:#000000"> </span>with<span style="color:#000000"> </span>the<span style="color:#000000"> </span>integer<span style="color:#000000"> </span>1.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">id</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>offset<span style="color:#000000"> </span>after<span style="color:#000000"> </span>the<span style="color:#000000"> </span>chunk<span style="color:#000000"> </span>is<span style="color:#000000"> </span>added<span style="color:#000000"> </span>to<span style="color:#000000"> </span>the<span style="color:#000000"> </span>file.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>long<span style="color:#000000"> </span><span style="color:#0000c0">offset</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>default<span style="color:#000000"> </span>size<span style="color:#000000"> </span>of<span style="color:#000000"> </span>a<span style="color:#000000"> </span>chunk.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">chunkSize</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>length<span style="color:#000000"> </span>of<span style="color:#000000"> </span>the<span style="color:#000000"> </span>file.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">fileLength</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>The<span style="color:#000000"> </span>filename.</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">final</span> String <span style="color:#0000c0">fileName</span>;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>public<span style="color:#000000"> </span>final<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">numberOfChunks</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> KarmaFileChunk(UUID uuid, <span style="color:#7f0055">final</span> <span style="color:#7f0055">byte</span>[] bytes, <span style="color:#7f0055">final</span> <span style="color:#7f0055">int</span> id,</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">final</span> <span style="color:#7f0055">long</span> offset, <span style="color:#7f0055">final</span> <span style="color:#7f0055">int</span> chunkSize, <span style="color:#7f0055">final</span> <span style="color:#7f0055">int</span> fileLength,</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">boolean</span> isLast, String fileName) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span> = uuid;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">bytes</span> = bytes;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">id</span> = id;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">offset</span> = offset;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">chunkSize</span> = chunkSize;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileLength</span> = fileLength;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">isLast</span> = isLast;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span> = fileName;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (!<span style="color:#7f0055">this</span>.<span style="color:#0000c0">isLast</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">numberOfChunks</span> = (fileLength / chunkSize)</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                                        </span>+ (((fileLength % chunkSize) &gt; 0) ? 1 : 0);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"><span style="color:#000000"><span style="white-space:pre">                        </span></span><span style="color:#7f0055">this</span><span style="color:#000000">.</span>numberOfChunks<span style="color:#000000"> = </span><span style="color:#7f0055">this</span><span style="color:#000000">.</span>id<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">int</span> compareTo(KarmaFileChunk chunk) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">int</span> result = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span> == chunk) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>result = -1;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (chunk == <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>result = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (chunk.hashCode() &gt; <span style="color:#7f0055">this</span>.hashCode()) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>result = +1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> <span style="color:#7f0055">if</span> (chunk.hashCode() &lt; <span style="color:#7f0055">this</span>.hashCode()) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>result = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> <span style="color:#7f0055">if</span> (chunk.equals(<span style="color:#7f0055">this</span>)) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>result = 0;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 127, 95)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>// Probably impossible.</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span>result = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">return</span> result;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(100, 100, 100)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>@Override</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> String toString() {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">return</span> <span style="color:#7f0055">this</span>.getClass().getSimpleName() + hashCode()</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                </span>+ </span>" \n\tfile uuid: "<span style="color:#000000"> + </span><span style="color:#0000c0">uuid</span><span style="color:#000000"> + </span>" offset="<span style="color:#000000"> + </span><span style="color:#0000c0">offset</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                </span>+ </span>" chunkSize="<span style="color:#000000"> + </span><span style="color:#0000c0">chunkSize</span><span style="color:#000000"> + </span>" bytes="<span style="color:#000000"> + </span><span style="color:#0000c0">bytes</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                </span>+ </span>" fileLength: "<span style="color:#000000"> + </span><span style="color:#0000c0">fileLength</span><span style="color:#000000"> + </span>" fileName: "<span style="color:#000000"> + </span><span style="color:#0000c0">fileName</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                </span>+ </span>" + isLast: "<span style="color:#000000"> + </span><span style="color:#0000c0">isLast</span><span style="color:#000000"> + </span>" numberOfChunks: "<span style="color:#000000"> + </span><span style="color:#0000c0">numberOfChunks</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                </span>+ </span>" chunk sequence id (number)="<span style="color:#000000"> + </span><span style="color:#0000c0">id</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(100, 100, 100)"><span style="color:#000000"><span style="white-space:pre">        </span></span>@Override</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">int</span> hashCode() {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">final</span> <span style="color:#7f0055">int</span> prime = 31;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">int</span> result = 1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>result = prime * result + Arrays.hashCode(<span style="color:#7f0055">this</span>.<span style="color:#0000c0">bytes</span>);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>result = prime * result + <span style="color:#7f0055">this</span>.<span style="color:#0000c0">chunkSize</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>result = prime * result + <span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileLength</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>result = prime * result</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                                </span>+ ((<span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span> == <span style="color:#7f0055">null</span>) ? 0 : <span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span>.hashCode());</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>result = prime * result + <span style="color:#7f0055">this</span>.<span style="color:#0000c0">id</span>;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>result = prime * result + (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">isLast</span> ? 1231 : 1237);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>result = prime * result + <span style="color:#7f0055">this</span>.<span style="color:#0000c0">numberOfChunks</span>;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>result = prime * result + (<span style="color:#7f0055">int</span>) (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">offset</span> ^ (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">offset</span> &gt;&gt;&gt; 32));</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>result = prime * result</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span>+ ((<span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span> == <span style="color:#7f0055">null</span>) ? 0 : <span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span>.hashCode());</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">return</span> result;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(100, 100, 100)"> <span style="color:#000000"><span style="white-space:pre">        </span></span>@Override</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">boolean</span> equals(Object obj) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span> == obj) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>true<span style="color:#000000">;</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (obj == <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (!(obj <span style="color:#7f0055">instanceof</span> KarmaFileChunk)) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>KarmaFileChunk other = (KarmaFileChunk) obj;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (!Arrays.equals(<span style="color:#7f0055">this</span>.<span style="color:#0000c0">bytes</span>, other.<span style="color:#0000c0">bytes</span>)) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">chunkSize</span> != other.<span style="color:#0000c0">chunkSize</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"> <span style="color:#000000"><span style="white-space:pre">                </span></span><span style="color:#7f0055">if</span><span style="color:#000000"> (</span><span style="color:#7f0055">this</span><span style="color:#000000">.</span>fileLength<span style="color:#000000"> != other.</span>fileLength<span style="color:#000000">) {</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span> == <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (other.<span style="color:#0000c0">fileName</span> != <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                                </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> <span style="color:#7f0055">if</span> (!<span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span>.equals(other.<span style="color:#0000c0">fileName</span>)) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">id</span> != other.<span style="color:#0000c0">id</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">isLast</span> != other.<span style="color:#0000c0">isLast</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"> <span style="color:#000000"><span style="white-space:pre">                </span></span><span style="color:#7f0055">if</span><span style="color:#000000"> (</span><span style="color:#7f0055">this</span><span style="color:#000000">.</span>numberOfChunks<span style="color:#000000"> != other.</span>numberOfChunks<span style="color:#000000">) {</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">offset</span> != other.<span style="color:#0000c0">offset</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span> == <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (other.<span style="color:#0000c0">uuid</span> != <span style="color:#7f0055">null</span>) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                                </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> <span style="color:#7f0055">if</span> (!<span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span>.equals(other.<span style="color:#0000c0">uuid</span>)) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                </span></span>return<span style="color:#000000"> </span>true<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> /**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 127, 159)"><span style="color:#000000">&nbsp;</span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span>&lt;p&gt;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span>Follows<span style="color:#000000"> </span>in<span style="color:#000000"> </span>general<span style="color:#000000"> </span>outline<span style="color:#000000"> </span>the<span style="color:#000000"> </span>JBoss<span style="color:#000000"> </span><span style="text-decoration:underline">Netty</span><span style="color:#000000"> </span><span style="color:#7f7f9f">&lt;code&gt;</span>ChunkedNioStream<span style="color:#7f7f9f">&lt;/code&gt;</span>.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f7f9f">&lt;code&gt;</span>KarmaChunkedInput<span style="color:#7f7f9f">&lt;/code&gt;</span><span style="color:#000000"> </span>extends<span style="color:#000000"> </span><span style="text-decoration:underline">Netty</span><span style="color:#000000"> </span><span style="color:#7f7f9f">&lt;code&gt;</span>ChunkedInput<span style="color:#7f7f9f">&lt;/code&gt;</span><span style="color:#000000"> </span>and</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span>adds<span style="color:#000000"> </span>a<span style="color:#000000"> </span>close<span style="color:#000000"> </span>method.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 127, 159)"><span style="color:#000000">&nbsp;</span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span>&lt;/p&gt;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">&nbsp;<span style="color:#3f5fbf">*</span>&nbsp;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@author</span><span style="color:#000000"> </span><span style="text-decoration:underline">Mike</span><span style="color:#000000"> </span>McGrady</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@version</span><span style="color:#000000"> </span><span style="text-decoration:underline">Karma</span><span style="color:#000000"> </span>Alpha<span style="color:#000000"> </span>v001</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@since</span><span style="color:#000000"> </span>August<span style="color:#000000"> </span>2009.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000">&nbsp;</span>*/</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="color:#7f0055">public</span> <span style="color:#7f0055">class</span> KarmaChunkedNioStream <span style="color:#7f0055">implements</span> KarmaChunkedInput {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">private</span> <span style="color:#7f0055">static</span> <span style="color:#7f0055">final</span> InternalLogger <span style="color:#0000c0">logger</span> = InternalLoggerFactory</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>.getInstance(KarmaChunkedNioStream.<span style="color:#7f0055">class</span>.getName());</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"> <span style="color:#000000"><span style="white-space:pre">        </span></span><span style="color:#7f0055">static</span><span style="color:#000000"> </span><span style="color:#7f0055">final</span><span style="color:#000000"> </span><span style="color:#7f0055">int</span><span style="color:#000000"> </span>DEFAULT_CHUNK_SIZE<span style="color:#000000"> = 8192;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>final<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">length</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>final<span style="color:#000000"> UUID </span><span style="color:#0000c0">uuid</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">private</span> <span style="color:#7f0055">final</span> ReadableByteChannel <span style="color:#0000c0">in</span>;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">id</span><span style="color:#000000"> = 1;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>final<span style="color:#000000"> String </span><span style="color:#0000c0">fileName</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>int<span style="color:#000000"> </span><span style="color:#0000c0">chunkSize</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">        </span></span>private<span style="color:#000000"> </span>volatile<span style="color:#000000"> </span>long<span style="color:#000000"> </span><span style="color:#0000c0">offset</span><span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>Associated<span style="color:#000000"> </span>ByteBuffer</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">private</span> ByteBuffer <span style="color:#0000c0">byteBuffer</span> = <span style="color:#7f0055">null</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>Creates<span style="color:#000000"> </span>a<span style="color:#000000"> </span>new<span style="color:#000000"> </span>instance<span style="color:#000000"> </span>that<span style="color:#000000"> </span>fetches<span style="color:#000000"> </span>data<span style="color:#000000"> </span>from<span style="color:#000000"> </span>the<span style="color:#000000"> </span>specified<span style="color:#000000"> </span>channel.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> KarmaChunkedNioStream(<span style="color:#7f0055">int</span> length, ReadableByteChannel in, File file,</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span>UUID uuid) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>(length, in, <span style="color:#0000c0">DEFAULT_CHUNK_SIZE</span>, file, uuid);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@param</span><span style="color:#000000"> </span>length</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 159, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span>@param<span style="color:#000000"> </span><span style="color:#3f5fbf">in</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span><span style="color:#7f9fbf">@param</span><span style="color:#000000"> </span>chunkSize</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 159, 191)"><span style="color:#000000"><span style="white-space:pre">        </span> </span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span>@param<span style="color:#000000"> </span><span style="color:#3f5fbf">file</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 159, 191)"><span style="color:#000000"><span style="white-space:pre">        </span> </span><span style="color:#3f5fbf">*</span><span style="color:#000000"> </span>@param<span style="color:#000000"> </span><span style="color:#3f5fbf">uuid</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color:#7f7f9f">&lt;code&gt;</span>KarmaManager<span style="color:#7f7f9f">&lt;/code&gt;</span><span style="color:#000000"> </span>ID.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> KarmaChunkedNioStream(<span style="color:#7f0055">int</span> length, ReadableByteChannel in,</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">int</span> chunkSize, File file, UUID uuid) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">length</span> = length;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span> = uuid;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (in == <span style="color:#7f0055">null</span>) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">throw</span> <span style="color:#7f0055">new</span> NullPointerException(<span style="color:#2a00ff">"in"</span>);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (chunkSize &lt;= 0) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">throw</span> <span style="color:#7f0055">new</span> IllegalArgumentException(<span style="color:#2a00ff">"chunkSize: "</span> + chunkSize</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(42, 0, 255)"><span style="color:#000000"><span style="white-space:pre">                                        </span>+ </span>" (expected: a positive integer)"<span style="color:#000000">);</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">in</span> = in;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#0000c0">offset</span> = 0;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">chunkSize</span> = chunkSize;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#0000c0">byteBuffer</span> != <span style="color:#7f0055">null</span>) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (<span style="color:#0000c0">byteBuffer</span>.capacity() != chunkSize) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"> <span style="color:#000000"><span style="white-space:pre">                                </span></span>byteBuffer<span style="color:#000000"> = </span><span style="color:#7f0055">null</span><span style="color:#000000">;</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#0000c0">byteBuffer</span> = ByteBuffer.allocate(chunkSize);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#0000c0">byteBuffer</span> = ByteBuffer.allocate(chunkSize);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">this</span>.<span style="color:#0000c0">fileName</span> = file.getName();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"><span style="color:#000000"><span style="white-space:pre">        </span></span>/**</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 95, 191)"> <span style="color:#000000"><span style="white-space:pre">        </span> </span>*<span style="color:#000000"> </span>Returns<span style="color:#000000"> </span>the<span style="color:#000000"> </span>number<span style="color:#000000"> </span>of<span style="color:#000000"> </span>transferred<span style="color:#000000"> </span>bytes.</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span> <span style="color:#3f5fbf">*/</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">long</span> getTransferredBytes() {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"> <span style="color:#000000"><span style="white-space:pre">                </span></span>return<span style="color:#000000"> </span><span style="color:#0000c0">offset</span><span style="color:#000000">;</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">boolean</span> hasNextChunk() {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#0000c0">byteBuffer</span>.position() &gt; 0) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 127, 95)"> <span style="color:#000000"><span style="white-space:pre">                        </span></span>// A previous read was not over, so there is a next chunk in the</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 127, 95)"> <span style="color:#000000"><span style="white-space:pre">                        </span></span>// buffer at least</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>true<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (<span style="color:#0000c0">in</span>.isOpen()) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 127, 95)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>// Try to read a new part, and keep this part (no rewind)</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">int</span> b = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">try</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                                </span>b = <span style="color:#0000c0">in</span>.read(<span style="color:#0000c0">byteBuffer</span>);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>} <span style="color:#7f0055">catch</span> (IOException e) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#0000c0">logger</span>.log(InternalLogLevel.<span style="color:#0000c0">ERROR</span>, e.getMessage());</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span>e.printStackTrace();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (b &lt; 0) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                                </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>} <span style="color:#7f0055">else</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#0000c0">offset</span> += b;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                                </span></span>return<span style="color:#000000"> </span>true<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                </span></span>return<span style="color:#000000"> </span>false<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br> </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span><span style="color:#7f0055">public</span> <span style="color:#7f0055">void</span> close() {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#7f0055">try</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#0000c0">in</span>.close();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>} <span style="color:#7f0055">catch</span> (IOException e) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#0000c0">logger</span>.log(InternalLogLevel.<span style="color:#0000c0">ERROR</span>, e.getMessage());</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span>e.printStackTrace();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">        </span><span style="color:#7f0055">public</span> KarmaFileChunk nextChunk() {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">if</span> (!hasNextChunk()) {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(127, 0, 85)"><span style="color:#000000"><span style="white-space:pre">                        </span></span>return<span style="color:#000000"> </span>null<span style="color:#000000">;</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(63, 127, 95)"> <span style="color:#000000"><span style="white-space:pre">                </span></span>// buffer cannot be empty from there</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">int</span> readBytes = <span style="color:#0000c0">byteBuffer</span>.position();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">for</span> (;;) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">int</span> localReadBytes = -1;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">try</span> {</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                                </span>localReadBytes = <span style="color:#0000c0">in</span>.read(<span style="color:#0000c0">byteBuffer</span>);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>} <span style="color:#7f0055">catch</span> (IOException e) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#0000c0">logger</span>.log(InternalLogLevel.<span style="color:#0000c0">ERROR</span>, e.getMessage());</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span>e.printStackTrace();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (localReadBytes &lt; 0) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#7f0055">break</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>readBytes += localReadBytes;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#0000c0">offset</span> += localReadBytes;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                        </span><span style="color:#7f0055">if</span> (readBytes == <span style="color:#0000c0">chunkSize</span>) {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                                </span><span style="color:#7f0055">break</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#0000c0">byteBuffer</span>.flip();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">int</span> lim = <span style="color:#0000c0">byteBuffer</span>.limit();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">byte</span>[] chunk = <span style="color:#7f0055">null</span>;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"><span style="color:#000000"><span style="white-space:pre">                </span></span><span style="color:#7f0055">if</span><span style="color:#000000"> (lim == </span>DEFAULT_CHUNK_SIZE<span style="color:#000000">) {</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>chunk = <span style="color:#0000c0">byteBuffer</span>.array();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>} <span style="color:#7f0055">else</span> {</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span>chunk = <span style="color:#7f0055">new</span> <span style="color:#7f0055">byte</span>[lim];</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                        </span><span style="color:#0000c0">byteBuffer</span>.get(chunk);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre">                </span><span style="color:#0000c0">byteBuffer</span>.clear();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span>KarmaFileChunk karmaChunk = <span style="color:#7f0055">new</span> KarmaFileChunk(<span style="color:#7f0055">this</span>.<span style="color:#0000c0">uuid</span>, chunk, <span style="color:#0000c0">id</span>++,</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(0, 0, 192)"><span style="color:#000000"><span style="white-space:pre">                                </span></span><span style="color:#7f0055">this</span><span style="color:#000000">.</span>offset<span style="color:#000000">, </span>chunkSize<span style="color:#000000"> = lim, </span>length<span style="color:#000000">,</span></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                                </span>((<span style="color:#0000c0">offset</span> == <span style="color:#0000c0">length</span>) ? <span style="color:#7f0055">true</span> : <span style="color:#7f0055">false</span>), <span style="color:#0000c0">fileName</span>);</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">                </span><span style="color:#7f0055">return</span> karmaChunk;</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre">        </span>}</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">}</div></div></span></font></span></font></div> <div><br><div><div>On Sep 14, 2009, at 9:44 AM, bgoetzmann wrote:</div><br><blockquote type="cite"><div><br>I just come to try the approach I spoke about, and it works.<br>Netty is really powerful!<br><br>Cheers,<br><br>Bertrand.<br> <br><br>bgoetzmann wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">Hello,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In my Netty project whose goal is to transfer large file form a client to<br> </blockquote><blockquote type="cite">a server, I used an ChunkedWriteHandler instance and a custom client<br></blockquote><blockquote type="cite">handler that uses the ChunkedFile class in order to send a file piece by<br> </blockquote><blockquote type="cite">piece. All is OK!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The next step for me would be to send first some information on the file<br></blockquote> <blockquote type="cite">that is about to be sent (name, size, etc.). So I need to send a POJO<br></blockquote><blockquote type="cite">instance.<br></blockquote><blockquote type="cite">What is the approach I can take? Can you tell me if this is a valid<br> </blockquote><blockquote type="cite">approach, having a POJO that holds the information I want on the file:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">* On the client side:<br></blockquote> <blockquote type="cite">- when connected, add a ObjectEncoder dynamically in the pipeline (or have<br></blockquote><blockquote type="cite">it already in the pipeline)<br></blockquote><blockquote type="cite">- populates the POJO and send it to server<br> </blockquote><blockquote type="cite">- remove the ObjectEncoder <br></blockquote><blockquote type="cite">- add the ChunkedWriteHandler in the pipeline<br></blockquote><blockquote type="cite">- send the file<br></blockquote> <blockquote type="cite"><br></blockquote><blockquote type="cite">* On the server side:<br></blockquote><blockquote type="cite">- when connected, add a ObjectDecoder dynamically in the pipeline (or have<br></blockquote><blockquote type="cite"> it already in the pipeline)<br></blockquote><blockquote type="cite">- receive the POJO and process its data<br></blockquote><blockquote type="cite">- remove the ObjectDecoder <br></blockquote><blockquote type="cite">- add a custom handler to handle messages containing file pieces<br> </blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Is there another way to process such scenario? Thank you for any help!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> <br></blockquote><blockquote type="cite">Bertrand.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><br>-- <br>View this message in context: <a href="http://n2.nabble.com/Process-different-types-of-messages-tp3643445p3643699.html" target="_blank">http://n2.nabble.com/Process-different-types-of-messages-tp3643445p3643699.html</a><br> Sent from the Netty User Group mailing list archive at Nabble.com.<br>_______________________________________________<br>netty-users mailing list<br><a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br></div></blockquote></div><br><div> <div style="word-wrap:break-word"><div style="word-wrap:break-word"> <span style="font-size:12px"><div style="word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word"> <span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word"> <div><div>Mike McGrady</div><div>Principal Investigator AF081-028 AFRL SBIR</div><div>Senior Engineer</div><div>Topia Technology, Inc</div><div>1.253.720.3365</div><div><a href="mailto:mmcgrady@topiatechnology.com" target="_blank">mmcgrady@topiatechnology.com</a></div> </div><div><br></div></div></span><br></div></span><br></div></span><br></div><br></div><br> </div><br></div></div><br>_______________________________________________<br> netty-users mailing list<br> <a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br> <br></blockquote></div><br></div> _______________________________________________<br>netty-users mailing list<br><a href="mailto:netty-users@lists.jboss.org">netty-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/netty-users<br></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Mike McGrady</div><div>Principal Investigator AF081-028 AFRL SBIR</div><div>Senior Engineer</div><div>Topia Technology, Inc</div><div>1.253.720.3365</div><div><a href="mailto:mmcgrady@topiatechnology.com">mmcgrady@topiatechnology.com</a></div></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></div></body></html>