hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [42/52] [partial] hbase-site git commit: Published site at 6d02f36ac78426f178b977566c170fb2e4b3503a.
Date Thu, 16 Jun 2016 22:39:40 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/b80ecc4e/apidocs/src-html/org/apache/hadoop/hbase/io/ByteBufferOutputStream.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/io/ByteBufferOutputStream.html b/apidocs/src-html/org/apache/hadoop/hbase/io/ByteBufferOutputStream.html
index d0f740b..c586dd5 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/io/ByteBufferOutputStream.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/io/ByteBufferOutputStream.html
@@ -52,139 +52,143 @@
 <span class="sourceLineNo">044</span>  // http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/util/ArrayList.java#221<a
name="line.44"></a>
 <span class="sourceLineNo">045</span>  private static final int MAX_ARRAY_SIZE
= Integer.MAX_VALUE - 8;<a name="line.45"></a>
 <span class="sourceLineNo">046</span><a name="line.46"></a>
-<span class="sourceLineNo">047</span>  protected ByteBuffer buf;<a name="line.47"></a>
+<span class="sourceLineNo">047</span>  protected ByteBuffer curBuf = null;<a
name="line.47"></a>
 <span class="sourceLineNo">048</span><a name="line.48"></a>
-<span class="sourceLineNo">049</span>  public ByteBufferOutputStream(int capacity)
{<a name="line.49"></a>
-<span class="sourceLineNo">050</span>    this(capacity, false);<a name="line.50"></a>
+<span class="sourceLineNo">049</span>  ByteBufferOutputStream() {<a name="line.49"></a>
+<span class="sourceLineNo">050</span><a name="line.50"></a>
 <span class="sourceLineNo">051</span>  }<a name="line.51"></a>
 <span class="sourceLineNo">052</span><a name="line.52"></a>
-<span class="sourceLineNo">053</span>  public ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) {<a name="line.53"></a>
-<span class="sourceLineNo">054</span>    this(allocate(capacity, useDirectByteBuffer));<a
name="line.54"></a>
+<span class="sourceLineNo">053</span>  public ByteBufferOutputStream(int capacity)
{<a name="line.53"></a>
+<span class="sourceLineNo">054</span>    this(capacity, false);<a name="line.54"></a>
 <span class="sourceLineNo">055</span>  }<a name="line.55"></a>
 <span class="sourceLineNo">056</span><a name="line.56"></a>
-<span class="sourceLineNo">057</span>  /**<a name="line.57"></a>
-<span class="sourceLineNo">058</span>   * @param bb ByteBuffer to use. If too
small, will be discarded and a new one allocated in its<a name="line.58"></a>
-<span class="sourceLineNo">059</span>   * place; i.e. the passed in BB may NOT
BE RETURNED!! Minimally it will be altered. SIDE EFFECT!!<a name="line.59"></a>
-<span class="sourceLineNo">060</span>   * If you want to get the newly allocated
ByteBuffer, you'll need to pick it up when<a name="line.60"></a>
-<span class="sourceLineNo">061</span>   * done with this instance by calling
{@link #getByteBuffer()}. All this encapsulation violation<a name="line.61"></a>
-<span class="sourceLineNo">062</span>   * is so we can recycle buffers rather
than allocate each time; it can get expensive especially<a name="line.62"></a>
-<span class="sourceLineNo">063</span>   * if the buffers are big doing allocations
each time or having them undergo resizing because<a name="line.63"></a>
-<span class="sourceLineNo">064</span>   * initial allocation was small.<a
name="line.64"></a>
-<span class="sourceLineNo">065</span>   * @see #getByteBuffer()<a name="line.65"></a>
-<span class="sourceLineNo">066</span>   */<a name="line.66"></a>
-<span class="sourceLineNo">067</span>  public ByteBufferOutputStream(final ByteBuffer
bb) {<a name="line.67"></a>
-<span class="sourceLineNo">068</span>    assert bb.order() == ByteOrder.BIG_ENDIAN;<a
name="line.68"></a>
-<span class="sourceLineNo">069</span>    this.buf = bb;<a name="line.69"></a>
-<span class="sourceLineNo">070</span>    this.buf.clear();<a name="line.70"></a>
-<span class="sourceLineNo">071</span>  }<a name="line.71"></a>
-<span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>  public int size() {<a name="line.73"></a>
-<span class="sourceLineNo">074</span>    return buf.position();<a name="line.74"></a>
+<span class="sourceLineNo">057</span>  public ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) {<a name="line.57"></a>
+<span class="sourceLineNo">058</span>    this(allocate(capacity, useDirectByteBuffer));<a
name="line.58"></a>
+<span class="sourceLineNo">059</span>  }<a name="line.59"></a>
+<span class="sourceLineNo">060</span><a name="line.60"></a>
+<span class="sourceLineNo">061</span>  /**<a name="line.61"></a>
+<span class="sourceLineNo">062</span>   * @param bb ByteBuffer to use. If too
small, will be discarded and a new one allocated in its<a name="line.62"></a>
+<span class="sourceLineNo">063</span>   * place; i.e. the passed in BB may NOT
BE RETURNED!! Minimally it will be altered. SIDE EFFECT!!<a name="line.63"></a>
+<span class="sourceLineNo">064</span>   * If you want to get the newly allocated
ByteBuffer, you'll need to pick it up when<a name="line.64"></a>
+<span class="sourceLineNo">065</span>   * done with this instance by calling
{@link #getByteBuffer()}. All this encapsulation violation<a name="line.65"></a>
+<span class="sourceLineNo">066</span>   * is so we can recycle buffers rather
than allocate each time; it can get expensive especially<a name="line.66"></a>
+<span class="sourceLineNo">067</span>   * if the buffers are big doing allocations
each time or having them undergo resizing because<a name="line.67"></a>
+<span class="sourceLineNo">068</span>   * initial allocation was small.<a
name="line.68"></a>
+<span class="sourceLineNo">069</span>   * @see #getByteBuffer()<a name="line.69"></a>
+<span class="sourceLineNo">070</span>   */<a name="line.70"></a>
+<span class="sourceLineNo">071</span>  public ByteBufferOutputStream(final ByteBuffer
bb) {<a name="line.71"></a>
+<span class="sourceLineNo">072</span>    assert bb.order() == ByteOrder.BIG_ENDIAN;<a
name="line.72"></a>
+<span class="sourceLineNo">073</span>    this.curBuf = bb;<a name="line.73"></a>
+<span class="sourceLineNo">074</span>    this.curBuf.clear();<a name="line.74"></a>
 <span class="sourceLineNo">075</span>  }<a name="line.75"></a>
 <span class="sourceLineNo">076</span><a name="line.76"></a>
-<span class="sourceLineNo">077</span>  private static ByteBuffer allocate(final
int capacity, final boolean useDirectByteBuffer) {<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    if (capacity &gt; MAX_ARRAY_SIZE)
{ // avoid OutOfMemoryError<a name="line.78"></a>
-<span class="sourceLineNo">079</span>      throw new BufferOverflowException();<a
name="line.79"></a>
-<span class="sourceLineNo">080</span>    }<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    return useDirectByteBuffer? ByteBuffer.allocateDirect(capacity):
ByteBuffer.allocate(capacity);<a name="line.81"></a>
-<span class="sourceLineNo">082</span>  }<a name="line.82"></a>
-<span class="sourceLineNo">083</span><a name="line.83"></a>
-<span class="sourceLineNo">084</span>  /**<a name="line.84"></a>
-<span class="sourceLineNo">085</span>   * This flips the underlying BB so be
sure to use it _last_!<a name="line.85"></a>
-<span class="sourceLineNo">086</span>   * @return ByteBuffer<a name="line.86"></a>
-<span class="sourceLineNo">087</span>   */<a name="line.87"></a>
-<span class="sourceLineNo">088</span>  public ByteBuffer getByteBuffer() {<a
name="line.88"></a>
-<span class="sourceLineNo">089</span>    buf.flip();<a name="line.89"></a>
-<span class="sourceLineNo">090</span>    return buf;<a name="line.90"></a>
-<span class="sourceLineNo">091</span>  }<a name="line.91"></a>
-<span class="sourceLineNo">092</span><a name="line.92"></a>
-<span class="sourceLineNo">093</span>  private void checkSizeAndGrow(int extra)
{<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    long capacityNeeded = buf.position()
+ (long) extra;<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    if (capacityNeeded &gt; buf.limit())
{<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      // guarantee it's possible to fit<a
name="line.96"></a>
-<span class="sourceLineNo">097</span>      if (capacityNeeded &gt; MAX_ARRAY_SIZE)
{<a name="line.97"></a>
-<span class="sourceLineNo">098</span>        throw new BufferOverflowException();<a
name="line.98"></a>
-<span class="sourceLineNo">099</span>      }<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      // double until hit the cap<a name="line.100"></a>
-<span class="sourceLineNo">101</span>      long nextCapacity = Math.min(buf.capacity()
* 2L, MAX_ARRAY_SIZE);<a name="line.101"></a>
-<span class="sourceLineNo">102</span>      // but make sure there is enough if
twice the existing capacity is still too small<a name="line.102"></a>
-<span class="sourceLineNo">103</span>      nextCapacity = Math.max(nextCapacity,
capacityNeeded);<a name="line.103"></a>
-<span class="sourceLineNo">104</span>      ByteBuffer newBuf = allocate((int)
nextCapacity, buf.isDirect());<a name="line.104"></a>
-<span class="sourceLineNo">105</span>      buf.flip();<a name="line.105"></a>
-<span class="sourceLineNo">106</span>      ByteBufferUtils.copyFromBufferToBuffer(buf,
newBuf);<a name="line.106"></a>
-<span class="sourceLineNo">107</span>      buf = newBuf;<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    }<a name="line.108"></a>
-<span class="sourceLineNo">109</span>  }<a name="line.109"></a>
-<span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>  // OutputStream<a name="line.111"></a>
-<span class="sourceLineNo">112</span>  @Override<a name="line.112"></a>
-<span class="sourceLineNo">113</span>  public void write(int b) throws IOException
{<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    checkSizeAndGrow(Bytes.SIZEOF_BYTE);<a
name="line.114"></a>
-<span class="sourceLineNo">115</span>    buf.put((byte)b);<a name="line.115"></a>
-<span class="sourceLineNo">116</span>  }<a name="line.116"></a>
-<span class="sourceLineNo">117</span><a name="line.117"></a>
-<span class="sourceLineNo">118</span> /**<a name="line.118"></a>
-<span class="sourceLineNo">119</span>  * Writes the complete contents of this
byte buffer output stream to<a name="line.119"></a>
-<span class="sourceLineNo">120</span>  * the specified output stream argument.<a
name="line.120"></a>
-<span class="sourceLineNo">121</span>  *<a name="line.121"></a>
-<span class="sourceLineNo">122</span>  * @param      out   the output stream
to which to write the data.<a name="line.122"></a>
-<span class="sourceLineNo">123</span>  * @exception  IOException  if an I/O error
occurs.<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  */<a name="line.124"></a>
-<span class="sourceLineNo">125</span>  public synchronized void writeTo(OutputStream
out) throws IOException {<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    WritableByteChannel channel = Channels.newChannel(out);<a
name="line.126"></a>
-<span class="sourceLineNo">127</span>    ByteBuffer bb = buf.duplicate();<a
name="line.127"></a>
-<span class="sourceLineNo">128</span>    bb.flip();<a name="line.128"></a>
-<span class="sourceLineNo">129</span>    channel.write(bb);<a name="line.129"></a>
-<span class="sourceLineNo">130</span>  }<a name="line.130"></a>
-<span class="sourceLineNo">131</span><a name="line.131"></a>
-<span class="sourceLineNo">132</span>  @Override<a name="line.132"></a>
-<span class="sourceLineNo">133</span>  public void write(byte[] b) throws IOException
{<a name="line.133"></a>
-<span class="sourceLineNo">134</span>    write(b, 0, b.length);<a name="line.134"></a>
-<span class="sourceLineNo">135</span>  }<a name="line.135"></a>
-<span class="sourceLineNo">136</span><a name="line.136"></a>
-<span class="sourceLineNo">137</span>  @Override<a name="line.137"></a>
-<span class="sourceLineNo">138</span>  public void write(byte[] b, int off, int
len) throws IOException {<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    checkSizeAndGrow(len);<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    ByteBufferUtils.copyFromArrayToBuffer(buf,
b, off, len);<a name="line.140"></a>
-<span class="sourceLineNo">141</span>  }<a name="line.141"></a>
-<span class="sourceLineNo">142</span><a name="line.142"></a>
-<span class="sourceLineNo">143</span>  public void write(ByteBuffer b, int off,
int len) throws IOException {<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    checkSizeAndGrow(len);<a name="line.144"></a>
-<span class="sourceLineNo">145</span>    ByteBufferUtils.copyFromBufferToBuffer(b,
buf, off, len);<a name="line.145"></a>
-<span class="sourceLineNo">146</span>  }<a name="line.146"></a>
-<span class="sourceLineNo">147</span><a name="line.147"></a>
-<span class="sourceLineNo">148</span>  /**<a name="line.148"></a>
-<span class="sourceLineNo">149</span>   * Writes an &lt;code&gt;int&lt;/code&gt;
to the underlying output stream as four<a name="line.149"></a>
-<span class="sourceLineNo">150</span>   * bytes, high byte first.<a name="line.150"></a>
-<span class="sourceLineNo">151</span>   * @param i the &lt;code&gt;int&lt;/code&gt;
to write<a name="line.151"></a>
-<span class="sourceLineNo">152</span>   * @throws IOException if an I/O error
occurs.<a name="line.152"></a>
-<span class="sourceLineNo">153</span>   */<a name="line.153"></a>
-<span class="sourceLineNo">154</span>  public void writeInt(int i) throws IOException
{<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    checkSizeAndGrow(Bytes.SIZEOF_INT);<a
name="line.155"></a>
-<span class="sourceLineNo">156</span>    ByteBufferUtils.putInt(this.buf, i);<a
name="line.156"></a>
-<span class="sourceLineNo">157</span>  }<a name="line.157"></a>
-<span class="sourceLineNo">158</span><a name="line.158"></a>
-<span class="sourceLineNo">159</span>  @Override<a name="line.159"></a>
-<span class="sourceLineNo">160</span>  public void flush() throws IOException
{<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    // noop<a name="line.161"></a>
-<span class="sourceLineNo">162</span>  }<a name="line.162"></a>
-<span class="sourceLineNo">163</span><a name="line.163"></a>
-<span class="sourceLineNo">164</span>  @Override<a name="line.164"></a>
-<span class="sourceLineNo">165</span>  public void close() throws IOException
{<a name="line.165"></a>
-<span class="sourceLineNo">166</span>    // noop again. heh<a name="line.166"></a>
-<span class="sourceLineNo">167</span>  }<a name="line.167"></a>
-<span class="sourceLineNo">168</span><a name="line.168"></a>
-<span class="sourceLineNo">169</span>  public byte[] toByteArray(int offset,
int length) {<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    ByteBuffer bb = buf.duplicate();<a
name="line.170"></a>
-<span class="sourceLineNo">171</span>    bb.flip();<a name="line.171"></a>
+<span class="sourceLineNo">077</span>  public int size() {<a name="line.77"></a>
+<span class="sourceLineNo">078</span>    return curBuf.position();<a name="line.78"></a>
+<span class="sourceLineNo">079</span>  }<a name="line.79"></a>
+<span class="sourceLineNo">080</span><a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private static ByteBuffer allocate(final
int capacity, final boolean useDirectByteBuffer) {<a name="line.81"></a>
+<span class="sourceLineNo">082</span>    if (capacity &gt; MAX_ARRAY_SIZE)
{ // avoid OutOfMemoryError<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      throw new BufferOverflowException();<a
name="line.83"></a>
+<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    return useDirectByteBuffer? ByteBuffer.allocateDirect(capacity):
ByteBuffer.allocate(capacity);<a name="line.85"></a>
+<span class="sourceLineNo">086</span>  }<a name="line.86"></a>
+<span class="sourceLineNo">087</span><a name="line.87"></a>
+<span class="sourceLineNo">088</span>  /**<a name="line.88"></a>
+<span class="sourceLineNo">089</span>   * This flips the underlying BB so be
sure to use it _last_!<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   * @return ByteBuffer<a name="line.90"></a>
+<span class="sourceLineNo">091</span>   */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>  public ByteBuffer getByteBuffer() {<a
name="line.92"></a>
+<span class="sourceLineNo">093</span>    curBuf.flip();<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    return curBuf;<a name="line.94"></a>
+<span class="sourceLineNo">095</span>  }<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>  protected void checkSizeAndGrow(int extra)
{<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    long capacityNeeded = curBuf.position()
+ (long) extra;<a name="line.98"></a>
+<span class="sourceLineNo">099</span>    if (capacityNeeded &gt; curBuf.limit())
{<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      // guarantee it's possible to fit<a
name="line.100"></a>
+<span class="sourceLineNo">101</span>      if (capacityNeeded &gt; MAX_ARRAY_SIZE)
{<a name="line.101"></a>
+<span class="sourceLineNo">102</span>        throw new BufferOverflowException();<a
name="line.102"></a>
+<span class="sourceLineNo">103</span>      }<a name="line.103"></a>
+<span class="sourceLineNo">104</span>      // double until hit the cap<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      long nextCapacity = Math.min(curBuf.capacity()
* 2L, MAX_ARRAY_SIZE);<a name="line.105"></a>
+<span class="sourceLineNo">106</span>      // but make sure there is enough if
twice the existing capacity is still too small<a name="line.106"></a>
+<span class="sourceLineNo">107</span>      nextCapacity = Math.max(nextCapacity,
capacityNeeded);<a name="line.107"></a>
+<span class="sourceLineNo">108</span>      ByteBuffer newBuf = allocate((int)
nextCapacity, curBuf.isDirect());<a name="line.108"></a>
+<span class="sourceLineNo">109</span>      curBuf.flip();<a name="line.109"></a>
+<span class="sourceLineNo">110</span>      ByteBufferUtils.copyFromBufferToBuffer(curBuf,
newBuf);<a name="line.110"></a>
+<span class="sourceLineNo">111</span>      curBuf = newBuf;<a name="line.111"></a>
+<span class="sourceLineNo">112</span>    }<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  }<a name="line.113"></a>
+<span class="sourceLineNo">114</span><a name="line.114"></a>
+<span class="sourceLineNo">115</span>  // OutputStream<a name="line.115"></a>
+<span class="sourceLineNo">116</span>  @Override<a name="line.116"></a>
+<span class="sourceLineNo">117</span>  public void write(int b) throws IOException
{<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    checkSizeAndGrow(Bytes.SIZEOF_BYTE);<a
name="line.118"></a>
+<span class="sourceLineNo">119</span>    curBuf.put((byte)b);<a name="line.119"></a>
+<span class="sourceLineNo">120</span>  }<a name="line.120"></a>
+<span class="sourceLineNo">121</span><a name="line.121"></a>
+<span class="sourceLineNo">122</span> /**<a name="line.122"></a>
+<span class="sourceLineNo">123</span>  * Writes the complete contents of this
byte buffer output stream to<a name="line.123"></a>
+<span class="sourceLineNo">124</span>  * the specified output stream argument.<a
name="line.124"></a>
+<span class="sourceLineNo">125</span>  *<a name="line.125"></a>
+<span class="sourceLineNo">126</span>  * @param      out   the output stream
to which to write the data.<a name="line.126"></a>
+<span class="sourceLineNo">127</span>  * @exception  IOException  if an I/O error
occurs.<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  */<a name="line.128"></a>
+<span class="sourceLineNo">129</span>  public void writeTo(OutputStream out)
throws IOException {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    WritableByteChannel channel = Channels.newChannel(out);<a
name="line.130"></a>
+<span class="sourceLineNo">131</span>    ByteBuffer bb = curBuf.duplicate();<a
name="line.131"></a>
+<span class="sourceLineNo">132</span>    bb.flip();<a name="line.132"></a>
+<span class="sourceLineNo">133</span>    channel.write(bb);<a name="line.133"></a>
+<span class="sourceLineNo">134</span>  }<a name="line.134"></a>
+<span class="sourceLineNo">135</span><a name="line.135"></a>
+<span class="sourceLineNo">136</span>  @Override<a name="line.136"></a>
+<span class="sourceLineNo">137</span>  public void write(byte[] b) throws IOException
{<a name="line.137"></a>
+<span class="sourceLineNo">138</span>    write(b, 0, b.length);<a name="line.138"></a>
+<span class="sourceLineNo">139</span>  }<a name="line.139"></a>
+<span class="sourceLineNo">140</span><a name="line.140"></a>
+<span class="sourceLineNo">141</span>  @Override<a name="line.141"></a>
+<span class="sourceLineNo">142</span>  public void write(byte[] b, int off, int
len) throws IOException {<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    checkSizeAndGrow(len);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    ByteBufferUtils.copyFromArrayToBuffer(curBuf,
b, off, len);<a name="line.144"></a>
+<span class="sourceLineNo">145</span>  }<a name="line.145"></a>
+<span class="sourceLineNo">146</span><a name="line.146"></a>
+<span class="sourceLineNo">147</span>  public void write(ByteBuffer b, int off,
int len) throws IOException {<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    checkSizeAndGrow(len);<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    ByteBufferUtils.copyFromBufferToBuffer(b,
curBuf, off, len);<a name="line.149"></a>
+<span class="sourceLineNo">150</span>  }<a name="line.150"></a>
+<span class="sourceLineNo">151</span><a name="line.151"></a>
+<span class="sourceLineNo">152</span>  /**<a name="line.152"></a>
+<span class="sourceLineNo">153</span>   * Writes an &lt;code&gt;int&lt;/code&gt;
to the underlying output stream as four<a name="line.153"></a>
+<span class="sourceLineNo">154</span>   * bytes, high byte first.<a name="line.154"></a>
+<span class="sourceLineNo">155</span>   * @param i the &lt;code&gt;int&lt;/code&gt;
to write<a name="line.155"></a>
+<span class="sourceLineNo">156</span>   * @throws IOException if an I/O error
occurs.<a name="line.156"></a>
+<span class="sourceLineNo">157</span>   */<a name="line.157"></a>
+<span class="sourceLineNo">158</span>  public void writeInt(int i) throws IOException
{<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    checkSizeAndGrow(Bytes.SIZEOF_INT);<a
name="line.159"></a>
+<span class="sourceLineNo">160</span>    ByteBufferUtils.putInt(this.curBuf,
i);<a name="line.160"></a>
+<span class="sourceLineNo">161</span>  }<a name="line.161"></a>
+<span class="sourceLineNo">162</span><a name="line.162"></a>
+<span class="sourceLineNo">163</span>  @Override<a name="line.163"></a>
+<span class="sourceLineNo">164</span>  public void flush() throws IOException
{<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    // noop<a name="line.165"></a>
+<span class="sourceLineNo">166</span>  }<a name="line.166"></a>
+<span class="sourceLineNo">167</span><a name="line.167"></a>
+<span class="sourceLineNo">168</span>  @Override<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  public void close() throws IOException
{<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    // noop again. heh<a name="line.170"></a>
+<span class="sourceLineNo">171</span>  }<a name="line.171"></a>
 <span class="sourceLineNo">172</span><a name="line.172"></a>
-<span class="sourceLineNo">173</span>    byte[] chunk = new byte[length];<a
name="line.173"></a>
-<span class="sourceLineNo">174</span><a name="line.174"></a>
-<span class="sourceLineNo">175</span>    bb.position(offset);<a name="line.175"></a>
-<span class="sourceLineNo">176</span>    bb.get(chunk, 0, length);<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    return chunk;<a name="line.177"></a>
-<span class="sourceLineNo">178</span>  }<a name="line.178"></a>
-<span class="sourceLineNo">179</span>}<a name="line.179"></a>
+<span class="sourceLineNo">173</span>  public byte[] toByteArray(int offset,
int length) {<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    ByteBuffer bb = curBuf.duplicate();<a
name="line.174"></a>
+<span class="sourceLineNo">175</span>    bb.flip();<a name="line.175"></a>
+<span class="sourceLineNo">176</span><a name="line.176"></a>
+<span class="sourceLineNo">177</span>    byte[] chunk = new byte[length];<a
name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>    bb.position(offset);<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    bb.get(chunk, 0, length);<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    return chunk;<a name="line.181"></a>
+<span class="sourceLineNo">182</span>  }<a name="line.182"></a>
+<span class="sourceLineNo">183</span>}<a name="line.183"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/b80ecc4e/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html b/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
index a1ab36a..2cffd19 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
@@ -61,7 +61,7 @@
 <span class="sourceLineNo">053</span>   */<a name="line.53"></a>
 <span class="sourceLineNo">054</span>  protected static class TableRecordWriter
implements RecordWriter&lt;ImmutableBytesWritable, Put&gt; {<a name="line.54"></a>
 <span class="sourceLineNo">055</span>    private BufferedMutator m_mutator;<a
name="line.55"></a>
-<span class="sourceLineNo">056</span><a name="line.56"></a>
+<span class="sourceLineNo">056</span>    private Connection connection;<a
name="line.56"></a>
 <span class="sourceLineNo">057</span>    /**<a name="line.57"></a>
 <span class="sourceLineNo">058</span>     * Instantiate a TableRecordWriter with
the HBase HClient for writing. Assumes control over the<a name="line.58"></a>
 <span class="sourceLineNo">059</span>     * lifecycle of {@code conn}.<a name="line.59"></a>
@@ -70,53 +70,57 @@
 <span class="sourceLineNo">062</span>      this.m_mutator = mutator;<a name="line.62"></a>
 <span class="sourceLineNo">063</span>    }<a name="line.63"></a>
 <span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>    public void close(Reporter reporter)
throws IOException {<a name="line.65"></a>
-<span class="sourceLineNo">066</span>      this.m_mutator.close();<a name="line.66"></a>
-<span class="sourceLineNo">067</span>    }<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>    public void write(ImmutableBytesWritable
key, Put value) throws IOException {<a name="line.69"></a>
-<span class="sourceLineNo">070</span>      m_mutator.mutate(new Put(value));<a
name="line.70"></a>
-<span class="sourceLineNo">071</span>    }<a name="line.71"></a>
-<span class="sourceLineNo">072</span>  }<a name="line.72"></a>
-<span class="sourceLineNo">073</span><a name="line.73"></a>
-<span class="sourceLineNo">074</span>  /**<a name="line.74"></a>
-<span class="sourceLineNo">075</span>   * Creates a new record writer.<a name="line.75"></a>
-<span class="sourceLineNo">076</span>   * <a name="line.76"></a>
-<span class="sourceLineNo">077</span>   * Be aware that the baseline javadoc
gives the impression that there is a single<a name="line.77"></a>
-<span class="sourceLineNo">078</span>   * {@link RecordWriter} per job but in
HBase, it is more natural if we give you a new<a name="line.78"></a>
-<span class="sourceLineNo">079</span>   * RecordWriter per call of this method.
You must close the returned RecordWriter when done.<a name="line.79"></a>
-<span class="sourceLineNo">080</span>   * Failure to do so will drop writes.<a
name="line.80"></a>
-<span class="sourceLineNo">081</span>   *<a name="line.81"></a>
-<span class="sourceLineNo">082</span>   * @param ignored Ignored filesystem<a
name="line.82"></a>
-<span class="sourceLineNo">083</span>   * @param job Current JobConf<a name="line.83"></a>
-<span class="sourceLineNo">084</span>   * @param name Name of the job<a name="line.84"></a>
-<span class="sourceLineNo">085</span>   * @param progress<a name="line.85"></a>
-<span class="sourceLineNo">086</span>   * @return The newly created writer instance.<a
name="line.86"></a>
-<span class="sourceLineNo">087</span>   * @throws IOException When creating the
writer fails.<a name="line.87"></a>
-<span class="sourceLineNo">088</span>   */<a name="line.88"></a>
-<span class="sourceLineNo">089</span>  @Override<a name="line.89"></a>
-<span class="sourceLineNo">090</span>  public RecordWriter getRecordWriter(FileSystem
ignored, JobConf job, String name,<a name="line.90"></a>
-<span class="sourceLineNo">091</span>      Progressable progress)<a name="line.91"></a>
-<span class="sourceLineNo">092</span>  throws IOException {<a name="line.92"></a>
-<span class="sourceLineNo">093</span>    // expecting exactly one path<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));<a
name="line.94"></a>
-<span class="sourceLineNo">095</span>    BufferedMutator mutator =  null;<a
name="line.95"></a>
-<span class="sourceLineNo">096</span>    // Connection is not closed. Dies with
JVM.  No possibility for cleanup.<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    Connection connection = ConnectionFactory.createConnection(job);<a
name="line.97"></a>
-<span class="sourceLineNo">098</span>    mutator = connection.getBufferedMutator(tableName);<a
name="line.98"></a>
-<span class="sourceLineNo">099</span>    // Clear write buffer on fail is true
by default so no need to reset it.<a name="line.99"></a>
-<span class="sourceLineNo">100</span>    return new TableRecordWriter(mutator);<a
name="line.100"></a>
-<span class="sourceLineNo">101</span>  }<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>  @Override<a name="line.103"></a>
-<span class="sourceLineNo">104</span>  public void checkOutputSpecs(FileSystem
ignored, JobConf job)<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  throws FileAlreadyExistsException, InvalidJobConfException,
IOException {<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    String tableName = job.get(OUTPUT_TABLE);<a
name="line.106"></a>
-<span class="sourceLineNo">107</span>    if (tableName == null) {<a name="line.107"></a>
-<span class="sourceLineNo">108</span>      throw new IOException("Must specify
table name");<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    }<a name="line.109"></a>
-<span class="sourceLineNo">110</span>  }<a name="line.110"></a>
-<span class="sourceLineNo">111</span>}<a name="line.111"></a>
+<span class="sourceLineNo">065</span>    public TableRecordWriter(JobConf job)
throws IOException {<a name="line.65"></a>
+<span class="sourceLineNo">066</span>      // expecting exactly one path<a
name="line.66"></a>
+<span class="sourceLineNo">067</span>      TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));<a
name="line.67"></a>
+<span class="sourceLineNo">068</span>      connection = ConnectionFactory.createConnection(job);<a
name="line.68"></a>
+<span class="sourceLineNo">069</span>      m_mutator = connection.getBufferedMutator(tableName);<a
name="line.69"></a>
+<span class="sourceLineNo">070</span>    }<a name="line.70"></a>
+<span class="sourceLineNo">071</span><a name="line.71"></a>
+<span class="sourceLineNo">072</span>    public void close(Reporter reporter)
throws IOException {<a name="line.72"></a>
+<span class="sourceLineNo">073</span>      this.m_mutator.close();<a name="line.73"></a>
+<span class="sourceLineNo">074</span>      if (connection != null) {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>        connection.close();<a name="line.75"></a>
+<span class="sourceLineNo">076</span>        connection = null;<a name="line.76"></a>
+<span class="sourceLineNo">077</span>      }<a name="line.77"></a>
+<span class="sourceLineNo">078</span>    }<a name="line.78"></a>
+<span class="sourceLineNo">079</span><a name="line.79"></a>
+<span class="sourceLineNo">080</span>    public void write(ImmutableBytesWritable
key, Put value) throws IOException {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      m_mutator.mutate(new Put(value));<a
name="line.81"></a>
+<span class="sourceLineNo">082</span>    }<a name="line.82"></a>
+<span class="sourceLineNo">083</span>  }<a name="line.83"></a>
+<span class="sourceLineNo">084</span><a name="line.84"></a>
+<span class="sourceLineNo">085</span>  /**<a name="line.85"></a>
+<span class="sourceLineNo">086</span>   * Creates a new record writer.<a name="line.86"></a>
+<span class="sourceLineNo">087</span>   * <a name="line.87"></a>
+<span class="sourceLineNo">088</span>   * Be aware that the baseline javadoc
gives the impression that there is a single<a name="line.88"></a>
+<span class="sourceLineNo">089</span>   * {@link RecordWriter} per job but in
HBase, it is more natural if we give you a new<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   * RecordWriter per call of this method.
You must close the returned RecordWriter when done.<a name="line.90"></a>
+<span class="sourceLineNo">091</span>   * Failure to do so will drop writes.<a
name="line.91"></a>
+<span class="sourceLineNo">092</span>   *<a name="line.92"></a>
+<span class="sourceLineNo">093</span>   * @param ignored Ignored filesystem<a
name="line.93"></a>
+<span class="sourceLineNo">094</span>   * @param job Current JobConf<a name="line.94"></a>
+<span class="sourceLineNo">095</span>   * @param name Name of the job<a name="line.95"></a>
+<span class="sourceLineNo">096</span>   * @param progress<a name="line.96"></a>
+<span class="sourceLineNo">097</span>   * @return The newly created writer instance.<a
name="line.97"></a>
+<span class="sourceLineNo">098</span>   * @throws IOException When creating the
writer fails.<a name="line.98"></a>
+<span class="sourceLineNo">099</span>   */<a name="line.99"></a>
+<span class="sourceLineNo">100</span>  @Override<a name="line.100"></a>
+<span class="sourceLineNo">101</span>  public RecordWriter getRecordWriter(FileSystem
ignored, JobConf job, String name,<a name="line.101"></a>
+<span class="sourceLineNo">102</span>      Progressable progress)<a name="line.102"></a>
+<span class="sourceLineNo">103</span>  throws IOException {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    return new TableRecordWriter(job);<a
name="line.104"></a>
+<span class="sourceLineNo">105</span>  }<a name="line.105"></a>
+<span class="sourceLineNo">106</span><a name="line.106"></a>
+<span class="sourceLineNo">107</span>  @Override<a name="line.107"></a>
+<span class="sourceLineNo">108</span>  public void checkOutputSpecs(FileSystem
ignored, JobConf job)<a name="line.108"></a>
+<span class="sourceLineNo">109</span>  throws FileAlreadyExistsException, InvalidJobConfException,
IOException {<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    String tableName = job.get(OUTPUT_TABLE);<a
name="line.110"></a>
+<span class="sourceLineNo">111</span>    if (tableName == null) {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      throw new IOException("Must specify
table name");<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
+<span class="sourceLineNo">114</span>  }<a name="line.114"></a>
+<span class="sourceLineNo">115</span>}<a name="line.115"></a>
 
 
 


Mime
View raw message