/**
 * 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.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author Kailash Dabhi
 * @date  22-08-2016.
 * Copyright (c) 2017 Kingbull Technology. All rights reserved.
 */
abstract class AbstractRecorder implements Recorder {
  protected final PullTransport pullTransport;
  protected final File file;
  private final OutputStream outputStream;

  protected AbstractRecorder(PullTransport pullTransport, File file) {
    this.pullTransport = pullTransport;
    this.file = file;
    this.outputStream = outputStream(file);
  }

  @Override public void startRecording() {
    new Thread(new Runnable() {
      @Override public void run() {
        try {
          pullTransport.start(outputStream);
        } catch (IOException e) {
          new RuntimeException(e);
        }
      }
    }).start();
  }

  private OutputStream outputStream(File file) {
    if (file == null) throw new RuntimeException("file is null !");
    OutputStream outputStream;
    try {
      outputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
      throw new RuntimeException("could not build OutputStream from" +
          " this file" + file.getName(), e);
    }
    return outputStream;
  }

  @Override public void stopRecording() {
    pullTransport.stop();
  }

  @Override public void pauseRecording() {
    pullTransport.source().isEnableToBePulled(false);
  }

  @Override public void resumeRecording() {
    pullTransport.source().isEnableToBePulled(true);
    startRecording();
  }
}

@@ -237,21 +237,16 @@
 at%0A *%0A *
-     
  http://
@@ -818,17 +818,16 @@
 * @date 
- 
 22-08-20
@@ -1260,162 +1260,194 @@
 %0A%0A  
-@Override public void startRecording() %7B%0A    new Thread(new Runnable() %7B%0A      @Override public void run() %7B%0A        try %7B%0A          pullTransport.start(o
+private OutputStream outputStream(File file) %7B%0A    if (file == null) throw new RuntimeException(%22file is null !%22);%0A    OutputStream outputStream;%0A    try %7B%0A      outputStream = new FileO
 utpu
@@ -1453,23 +1453,24 @@
 utStream
+(file
 );%0A
-    
     %7D ca
@@ -1474,18 +1474,28 @@
  catch (
-IO
+FileNotFound
 Exceptio
@@ -1507,19 +1507,21 @@
 %7B%0A      
-   
+throw
  new Run
@@ -1534,19 +1534,16 @@
 ception(
-e);
 %0A       
@@ -1547,173 +1547,274 @@
     
-%7D%0A      %7D%0A    %7D).start(
+  %22could not build OutputStream from%22 + %22 this file%22 + file.getName(), e
 );%0A
+  
   %7D%0A
-%0A  private OutputStream outputStream(File file) %7B%0A    if (file == null) throw new RuntimeException(%22file is null !%22);%0A    OutputStream 
+    return outputStream;%0A  %7D%0A%0A  @Override public void startRecording() %7B%0A    new Thread(new Runnable() %7B%0A      @Override public void run() %7B%0A        try %7B%0A          pullTransport.start(
 outp
@@ -1825,69 +1825,90 @@
 ream
+)
 ;%0A    
-try %7B%0A      outputStream = new FileOutputStream(file);%0A
+    %7D catch (IOException e) %7B%0A          throw new RuntimeException(e);%0A    
     
@@ -1912,36 +1912,36 @@
    %7D catch (
-FileNotFound
+IllegalState
 Exception e)
@@ -1935,32 +1935,36 @@
 eException e) %7B%0A
+    
       throw new 
@@ -1985,119 +1985,88 @@
 on(%22
-could not build OutputStream from%22 +%0A          %22 this file%22 + file.getName(), e);%0A    %7D%0A    return outputStream
+AudioRecord state has uninitialized state%22, e);%0A        %7D%0A      %7D%0A    %7D).start()
 ;%0A  

Throw exceptions instead of suppressing