/**
 * Copyright 2017 Kailash Dabhi (Kingbull Technology)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package omrecorder;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * {@code Wav} is recorder for recording audio in wav format.
 *
 * @author Kailash Dabhi
 * @date 31-07-2016
 */
final class Wav extends AbstractRecorder {
  private final RandomAccessFile wavFile;

  public Wav(PullTransport pullTransport, File file) {
    super(pullTransport, file);
    this.wavFile = randomAccessFile(file);
  }

  private RandomAccessFile randomAccessFile(File file) {
    RandomAccessFile randomAccessFile;
    try {
      randomAccessFile = new RandomAccessFile(file, "rw");
    } catch (FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    return randomAccessFile;
  }

  @Override public void stopRecording() {
    super.stopRecording();
    try {
      writeWavHeader();
    } catch (IOException e) {
    }
  }

  private void writeWavHeader() throws IOException {
    wavFile.seek(0); // to the beginning
    wavFile.write(new WavHeader(pullTransport.source(), file.length()).toBytes());
    wavFile.close();
  }
}
@@ -916,51 +916,8 @@
 r %7B%0A
-  private final RandomAccessFile wavFile;%0A%0A
   pu
@@ -1003,333 +1003,8 @@
 e);%0A
-    this.wavFile = randomAccessFile(file);%0A  %7D%0A%0A  private RandomAccessFile randomAccessFile(File file) %7B%0A    RandomAccessFile randomAccessFile;%0A    try %7B%0A      randomAccessFile = new RandomAccessFile(file, %22rw%22);%0A    %7D catch (FileNotFoundException e) %7B%0A      throw new RuntimeException(e);%0A    %7D%0A    return randomAccessFile;%0A
   %7D%0A
@@ -1133,24 +1133,93 @@
 eption e) %7B%0A
+      throw new RuntimeException(%22Error in applying wav header%22, e);%0A
     %7D%0A  %7D%0A%0A 
@@ -1270,16 +1270,77 @@
 ption %7B%0A
+    final RandomAccessFile wavFile = randomAccessFile(file);%0A
     wavF
@@ -1479,10 +1479,292 @@
 e();%0A  %7D
+%0A%0A  private RandomAccessFile randomAccessFile(File file) %7B%0A    RandomAccessFile randomAccessFile;%0A    try %7B%0A      randomAccessFile = new RandomAccessFile(file, %22rw%22);%0A    %7D catch (FileNotFoundException e) %7B%0A      throw new RuntimeException(e);%0A    %7D%0A    return randomAccessFile;%0A  %7D
 %0A%7D

Fix crash by Converting wavFile to local variable