Exemplo n.º 1
0
  /** Dummy Constructor */
  public RiffFile() {
    file = null;
    fmode = RFM_UNKNOWN;
    riff_header = new RiffChunkHeader();

    riff_header.ckID = FourCC("RIFF");
    riff_header.ckSize = 0;
  }
Exemplo n.º 2
0
  /** Open a RIFF file. */
  public int Open(String Filename, int NewMode) {
    int retcode = DDC_SUCCESS;

    if (fmode != RFM_UNKNOWN) {
      retcode = Close();
    }

    if (retcode == DDC_SUCCESS) {
      switch (NewMode) {
        case RFM_WRITE:
          try {
            file = new RandomAccessFile(Filename, "rw");

            try {
              // Write the RIFF header...
              // We will have to come back later and patch it!
              byte[] br = new byte[8];
              br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF);
              br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF);
              br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF);
              br[3] = (byte) (riff_header.ckID & 0x000000FF);

              byte br4 = (byte) ((riff_header.ckSize >>> 24) & 0x000000FF);
              byte br5 = (byte) ((riff_header.ckSize >>> 16) & 0x000000FF);
              byte br6 = (byte) ((riff_header.ckSize >>> 8) & 0x000000FF);
              byte br7 = (byte) (riff_header.ckSize & 0x000000FF);

              br[4] = br7;
              br[5] = br6;
              br[6] = br5;
              br[7] = br4;

              file.write(br, 0, 8);
              fmode = RFM_WRITE;
            } catch (IOException ioe) {
              file.close();
              fmode = RFM_UNKNOWN;
            }
          } catch (IOException ioe) {
            fmode = RFM_UNKNOWN;
            retcode = DDC_FILE_ERROR;
          }
          break;

        case RFM_READ:
          try {
            file = new RandomAccessFile(Filename, "r");
            try {
              // Try to read the RIFF header...
              byte[] br = new byte[8];
              file.read(br, 0, 8);
              fmode = RFM_READ;
              riff_header.ckID =
                  ((br[0] << 24) & 0xFF000000)
                      | ((br[1] << 16) & 0x00FF0000)
                      | ((br[2] << 8) & 0x0000FF00)
                      | (br[3] & 0x000000FF);
              riff_header.ckSize =
                  ((br[4] << 24) & 0xFF000000)
                      | ((br[5] << 16) & 0x00FF0000)
                      | ((br[6] << 8) & 0x0000FF00)
                      | (br[7] & 0x000000FF);
            } catch (IOException ioe) {
              file.close();
              fmode = RFM_UNKNOWN;
            }
          } catch (IOException ioe) {
            fmode = RFM_UNKNOWN;
            retcode = DDC_FILE_ERROR;
          }
          break;
        default:
          retcode = DDC_INVALID_CALL;
      }
    }
    return retcode;
  }