/*
(non-Javadoc)
@see net.timewalker.ffmq4.storage.data.impl.AbstractBlockBasedDataStore#writeDataBlock(byte[], int, int, int)
322624
@Override
	protected void writeDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreException
    {
    	byte[] blockData = new byte[blockSize];
    	System.arraycopy(data, offset, blockData, 0, len);
    	
    	dirtyBlockTable.markDirty(blockHandle, blockData);    	
    	journal.writeDataBlock(blockHandle, (long)blockHandle*blockSize, blockData);
    }
1097896
@Override
    public void write(int b) throws IOException {
        Exceptions.checkNotClosed(this.closed, this);
        Preconditions.checkState(this.currentFrame != null, "No current frame exists. Most likely no record is started.");

        int attemptCount = 0;
        int totalBytesWritten = 0;
        while (totalBytesWritten == 0 && attemptCount < 2) {
            // We attempt to write 1 byte. If append() says it wrote 0 bytes, it means the current frame is full. Seal it and create a new one.
            totalBytesWritten += this.currentFrame.append((byte) b);
            if (totalBytesWritten == 0) {
                this.currentFrame.endEntry(false); // Close the current entry, and indicate it is not the last one of the record.
                flush();
                createNewFrame();
                startNewRecordInCurrentFrame(false);
            }

            attemptCount++;
        }

        if (totalBytesWritten == 0) {
            throw new SerializationException("Unable to make progress in serializing to DataFrame.");
        }
    }
238965
static void getNumDataBytesAndNumECBytesForBlockID(int numTotalBytes,
                                                     int numDataBytes,
                                                     int numRSBlocks,
                                                     int blockID,
                                                     int[] numDataBytesInBlock,
                                                     int[] numECBytesInBlock) throws WriterException {
    if (blockID >= numRSBlocks) {
      throw new WriterException("Block ID too large");
    }
    // numRsBlocksInGroup2 = 196 % 5 = 1
    int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
    // numRsBlocksInGroup1 = 5 - 1 = 4
    int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
    // numTotalBytesInGroup1 = 196 / 5 = 39
    int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
    // numTotalBytesInGroup2 = 39 + 1 = 40
    int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
    // numDataBytesInGroup1 = 66 / 5 = 13
    int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
    // numDataBytesInGroup2 = 13 + 1 = 14
    int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
    // numEcBytesInGroup1 = 39 - 13 = 26
    int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
    // numEcBytesInGroup2 = 40 - 14 = 26
    int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
    // Sanity checks.
    // 26 = 26
    if (numEcBytesInGroup1 != numEcBytesInGroup2) {
      throw new WriterException("EC bytes mismatch");
    }
    // 5 = 4 + 1.
    if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) {
      throw new WriterException("RS blocks mismatch");
    }
    // 196 = (13 + 26) * 4 + (14 + 26) * 1
    if (numTotalBytes !=
        ((numDataBytesInGroup1 + numEcBytesInGroup1) *
            numRsBlocksInGroup1) +
            ((numDataBytesInGroup2 + numEcBytesInGroup2) *
                numRsBlocksInGroup2)) {
      throw new WriterException("Total bytes mismatch");
    }

    if (blockID < numRsBlocksInGroup1) {
      numDataBytesInBlock[0] = numDataBytesInGroup1;
      numECBytesInBlock[0] = numEcBytesInGroup1;
    } else {
      numDataBytesInBlock[0] = numDataBytesInGroup2;
      numECBytesInBlock[0] = numEcBytesInGroup2;
    }
  }
751484
private void writeBlockData(ByteBuf out) {
        final Bzip2BitWriter writer = this.writer;
        final int[][] huffmanMergedCodeSymbols = this.huffmanMergedCodeSymbols;
        final byte[] selectors = this.selectors;
        final char[] mtf = mtfBlock;
        final int mtfLength = this.mtfLength;

        int selectorIndex = 0;
        for (int mtfIndex = 0; mtfIndex < mtfLength;) {
            final int groupEnd = Math.min(mtfIndex + HUFFMAN_GROUP_RUN_LENGTH, mtfLength) - 1;
            final int[] tableMergedCodeSymbols = huffmanMergedCodeSymbols[selectors[selectorIndex++]];

            while (mtfIndex <= groupEnd) {
                final int mergedCodeSymbol = tableMergedCodeSymbols[mtf[mtfIndex++]];
                writer.writeBits(out, mergedCodeSymbol >>> 24, mergedCodeSymbol);
            }
        }
    }
416321
public final void write(byte[] data) {
    if (sendBinary) {
      int prev = 0;
      for (int i = 0;i < data.length;i++) {
        if (data[i] == -1) {
          rawWrite(data, prev, i - prev);
          send(new byte[]{-1, -1});
          prev = i + 1;
        }
      }
      rawWrite(data, prev, data.length - prev);
    } else {
      for (int i = 0;i < data.length;i++) {
        data[i] = (byte)(data[i] & 0x7F);
      }
      send(data);
    }
  }
1136297
def _writeblocks(cls, blocks, available, cont_size, padding_func):
        """"""

        # write everything except padding
        data = bytearray()
        for block in blocks:
            if isinstance(block, Padding):
                continue
            data += cls._writeblock(block)
        blockssize = len(data)

        # take the padding overhead into account. we always add one
        # to make things simple.
        padding_block = Padding()
        blockssize += len(cls._writeblock(padding_block))

        # finally add a padding block
        info = PaddingInfo(available - blockssize, cont_size)
        padding_block.length = min(info._get_padding(padding_func),
                                   cls._MAX_SIZE)
        data += cls._writeblock(padding_block, is_last=True)

        return data
185921
public void record(ByteBuffer block, int offset) {
    if (this.data == null) {
      // TODO: remove cast to int when large ByteBuffer support is
      // implemented in Java.
      this.data = ByteBuffer.allocate((int) this.length);
    }

    int pos = block.position();
    this.data.position(offset);
    this.data.put(block);
    block.position(pos);
  }
1115610
private function write_block()
    {
        if ($this->block_count > 0) {
            $this->encoder->write_long($this->block_count);
            $to_write = strval($this->buffer);
            $this->encoder->write_long(strlen($to_write));

            if (DataIO::is_valid_codec(
                $this->metadata[DataIO::METADATA_CODEC_ATTR])
            )
                $this->write($to_write);
            else
                throw new DataIOException(
                    sprintf('codec %s is not supported',
                        $this->metadata[DataIO::METADATA_CODEC_ATTR]));

            $this->write($this->sync_marker);
            $this->buffer->truncate();
            $this->block_count = 0;
        }
    }
620255
private static void writeHeader(DataOutputStream out, 
                                  BlockMetadataHeader header) 
                                  throws IOException {
    out.writeShort(header.getVersion());
    header.getChecksum().writeHeader(out);
  }
716598
public void write(DataOutput out) throws IOException {
    Text.writeString(out, getPath().toString());
    out.writeLong(length);
    out.writeBoolean(isdir);
    out.writeShort(block_replication);
    out.writeLong(blocksize);
    out.writeLong(modification_time);
    out.writeLong(access_time);
    permission.write(out);
    Text.writeStringOpt(out, owner);
    Text.writeStringOpt(out, group);
  }
1156083
public synchronized void write(int blockNumber, int blockOffset, int value) 
			throws IOException {
		long pointer = getBlockOffset(blockNumber) + blockOffset;
		if(mapped == true) {
			MappedByteBuffer map = NikeFS2FileAccessMonitor.instance().requestMap(this);
			map.position((int)pointer);
			map.put((byte)(value - 128));
		} else {
			rafile.seek(pointer);
			rafile.write(value);
		}
	}
1191251
private void flushBlock() throws IOException {
        if (this.debug) {
            System.err.println("TarBuffer.flushBlock() called.");
        }

        if (this.outStream == null) {
            throw new IOException("writing to an input buffer");
        }

        // Thanks to 'Todd Kofford <tkofford@bigfoot.com>' for this patch.
        // Use a buffer initialized with 0s to initialize everything in the
        // blockBuffer after the last current, complete record. This prevents
        // any previous data that might have previously existed in the
        // blockBuffer from being written to the file.

        if (this.currRecIdx > 0) {
            int offset = this.currRecIdx * this.recordSize;
            byte[] zeroBuffer = new byte[this.blockSize - offset];

            System.arraycopy(zeroBuffer, 0, this.blockBuffer, offset, zeroBuffer.length);

            this.writeBlock();
        }
    }
766627
private byte[] blockForWrite(int index) throws IOException {
    if (index >= blockCount) {
      int additionalBlocksNeeded = index - blockCount + 1;
      disk.allocate(this, additionalBlocksNeeded);
    }

    return blocks[index];
  }
997781
@Override
    public void write ( byte[] b, int off, int len ) throws IOException {
        writeDirect(b, off, len, 0);
    }
9574
public void writeFile(String filePath, byte[] data) throws IOException
   {
      Object lock = retrieveLock(filePath);      
      synchronized (lock) 
      {
         IO.writeFile(filePath, data);
      }
   }
267207
@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(this.partitionNumber);
		out.writeInt(this.totalNumberOfPartitions);
	}
251124
public static void dumpBlockData(int headerSize, int blockSize, byte[] data)
   {
      if (data != null)
      {
         System.out.println(ByteArrayHelper.hexdump(data, 0, headerSize, false));
         int index = headerSize;
         while (index < data.length)
         {
            System.out.println(ByteArrayHelper.hexdump(data, index, blockSize, false));
            index += blockSize;
         }
      }
   }