Ejemplo n.º 1
0
 public byte[] getFrame(int frame) {
   if (Sizes == null) {
     int StartOffset = HeaderSize;
     byte[] FrameData = new byte[data.length - HeaderSize];
     System.arraycopy(data, StartOffset, FrameData, 0, FrameData.length);
     return FrameData;
   }
   byte[] FrameData = new byte[Sizes[frame]];
   int StartOffset = HeaderSize;
   for (int s = 0; s < frame; s++) {
     StartOffset += Sizes[s];
   }
   System.arraycopy(data, StartOffset, FrameData, 0, FrameData.length);
   return FrameData;
 }
Ejemplo n.º 2
0
  // Faster than getFrame, but not as pretty.
  public int frameCopy(int frame, byte[] buffer, int bufferStartOffset) {
    int bytesCopied;
    if (Sizes == null) {
      int StartOffset = HeaderSize;
      bytesCopied = data.length - HeaderSize;
      if ((bufferStartOffset + bytesCopied) > buffer.length) {
        int copyToStart = ((bufferStartOffset + bytesCopied) - buffer.length);
        int copyToEnd = bytesCopied - copyToStart;
        System.arraycopy(data, StartOffset, buffer, bufferStartOffset, copyToEnd);
        System.arraycopy(data, StartOffset + copyToEnd, buffer, 0, copyToStart);
      } else {
        System.arraycopy(data, StartOffset, buffer, bufferStartOffset, bytesCopied);
      }
      return bytesCopied;
    }

    bytesCopied = Sizes[frame];
    int StartOffset = HeaderSize;
    for (int s = 0; s < frame; s++) {
      StartOffset += Sizes[s];
    }

    if ((bufferStartOffset + bytesCopied) > buffer.length) {
      int copyToStart = ((bufferStartOffset + bytesCopied) - buffer.length);
      int copyToEnd = bytesCopied - copyToStart;
      System.arraycopy(data, StartOffset, buffer, bufferStartOffset, copyToEnd);
      System.arraycopy(data, StartOffset + copyToEnd, buffer, 0, copyToStart);
    } else {
      System.arraycopy(data, StartOffset, buffer, bufferStartOffset, bytesCopied);
    }
    return bytesCopied;
  }