[TACHYON-152] Client write refactor

Rewriting how client writes out blocks to make it easier to add remote blocks.

The current design is as follows:

Users requests access to a block for writing.

```java
WritableBlockChannel channel = Blocks.createWritableBlock(tachyonFS, blockId, blockCapacityByte);
channel.write(byteBuffer);
channel.close();
```

When the block is full, write returns -1, so you do this in a loop and create new blocks.

```java
while (buffer.remaining() > 0) {
  int n = mCurrentBlockChannel.write(buffer);
  if (n <= 0) {
    // block full, get new block
    getNextBlock();
  }
}
```
Nah, if anything goes wrong we need to cancel.
On Sep 19, 2014 12:21 PM, "Henry Saputra" <notifications@github.com> wrote:

> In core/src/main/java/tachyon/client/TachyonFile.java:
>
> > -            } catch (IOException e) {
> > -              LOG.warn(e.getMessage(), e);
> > -              succeed = false;
> > -              break;
> > -            }
> > -          }
> > +        long length = getBlockSizeByte();
> > +        long offset = blockIndex * length;
> > +        inputStream.skip(offset);
> > +
> > +        WritableBlockChannel channel = Blocks.createWritableBlock(this, blockIndex);
> > +        try {
> > +          Blocks.copy(inputStream, channel, length);
> > +          channel.close();
> > +        } catch (IOException e){
> > +          channel.cancel();
>
> Should this be in finally block?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/amplab/tachyon/pull/427/files#r17804060>.
>