code: @Override
      public SeekableByteChannel truncate(final long size) throws IOException {
  
          // Precondition checks
          if (size < 0 || size > Integer.MAX_VALUE) {
              throw new IllegalArgumentException("This implementation permits a size of 0 to " + Integer.MAX_VALUE
                  + " inclusive");
          }
  
          // Sync up for mucking w/ shared mutable state
          synchronized (this) {
  
              final int newSize = (int) size;
              final int currentSize = (int) this.size();
  
              // If the current position is greater than the given size, set to the given size (by API spec)
              if (this.position > newSize) {
                  this.position = newSize;
              }
  
              // If we've been given a size smaller than we currently are
              if (currentSize > newSize) {
                  // Make new array
                  final byte[] newContents = new byte[newSize];
                  // Copy in the contents up to the new size
                  System.arraycopy(this.contents, 0, newContents, 0, newSize);
                  // Set the new array as our contents
                  this.contents = newContents;
              }
  
              // If we've been given a size greater than or equal to us then do nothing
              // if (newSize >= currentSize) {
              // // do nothing
              // }
          }
  
          // Return this reference
          return this;
      }
docs: {@inheritDoc}
  
  @see java.nio.channels.SeekableByteChannel#truncate(long)