Esempio n. 1
0
  public void AddData(byte[] pData, int nBytes) throws IOException {
    int nBytesDone = 0;

    while (nBytesDone < nBytes) {
      // lock the buffer
      m_nAddDataBytesAvailable.value = 0;
      ByteBuffer pBuffer = LockBuffer(m_nAddDataBytesAvailable);
      if (pBuffer == null || m_nAddDataBytesAvailable.value <= 0)
        throw new JMACException("Error Undefined");

      // calculate how many bytes to copy and add that much to the buffer
      int nBytesToProcess = Math.min(m_nAddDataBytesAvailable.value, nBytes - nBytesDone);
      pBuffer.append(pData, nBytesDone, nBytesToProcess);

      // unlock the buffer (fail if not successful)
      UnlockBuffer(nBytesToProcess);

      // update our progress
      nBytesDone += nBytesToProcess;
    }
  }
Esempio n. 2
0
  public ByteBuffer LockBuffer(IntegerPointer pBytesAvailable) {
    if (m_pBuffer == null) {
      return null;
    }

    if (m_bBufferLocked) return null;

    m_bBufferLocked = true;

    if (pBytesAvailable != null) pBytesAvailable.value = GetBufferBytesAvailable();

    pBufferPointer.reset(m_pBuffer, m_nBufferTail);
    return pBufferPointer;
  }