private void ProcessBuffer(boolean bFinalize) throws IOException {
    if (m_pBuffer == null) throw new JMACException("Error Undefined");

    // process as much as possible
    int nThreshold = (bFinalize) ? 0 : m_spAPECompressCreate.GetFullFrameBytes();

    while ((m_nBufferTail - m_nBufferHead) >= nThreshold) {
      int nFrameBytes =
          Math.min(m_spAPECompressCreate.GetFullFrameBytes(), m_nBufferTail - m_nBufferHead);

      if (nFrameBytes == 0) break;

      pByteReader.reset(m_pBuffer, m_nBufferHead);
      m_spAPECompressCreate.EncodeFrame(pByteReader, nFrameBytes);

      m_nBufferHead += nFrameBytes;
    }

    // shift the buffer
    if (m_nBufferHead != 0) {
      int nBytesLeft = m_nBufferTail - m_nBufferHead;

      if (nBytesLeft != 0) System.arraycopy(m_pBuffer, m_nBufferHead, m_pBuffer, 0, nBytesLeft);

      m_nBufferTail -= m_nBufferHead;
      m_nBufferHead = 0;
    }
  }
Exemple #2
0
 public static ID3Tag read(final File file) throws IOException {
   long offset = file.length() - ID3_TAG_BYTES;
   if (offset < 0) return null;
   file.seek(offset);
   try {
     final ID3Tag tag = new ID3Tag();
     final ByteArrayReader reader = new ByteArrayReader(file, ID3_TAG_BYTES);
     tag.Header = reader.readString(3, defaultEncoding);
     tag.Title = reader.readString(30, defaultEncoding);
     tag.Artist = reader.readString(30, defaultEncoding);
     tag.Album = reader.readString(30, defaultEncoding);
     tag.Year = reader.readString(4, defaultEncoding);
     tag.Comment = reader.readString(29, defaultEncoding);
     tag.Track = reader.readUnsignedByte();
     tag.Genre = reader.readUnsignedByte();
     return tag.Header.equals("TAG") ? tag : null;
   } catch (EOFException e) {
     return null;
   }
 }