// Path: src/main/java/jocket/wait/BusyYieldSleep.java
// public class BusyYieldSleep implements WaitStrategy {
// 
//   public static final int SPIN = 1000000;
// 
//   public static final int YIELD = SPIN + 1;
// 
//   public static final int SLEEP = YIELD + 1;
// 
//   private int counter;
// 
//   @Override
//   public void pauseWhile(int seq) {
//     int counter = this.counter++;
//     if (counter < SPIN)
//       return;
//     else if (counter < YIELD)
//       Thread.yield();
//     else if (counter < SLEEP)
//       LockSupport.parkNanos(1);
//     else {
//       this.counter = 0;
//     }
//   }
// 
//   @Override
//   public void reset() {
//     counter = 0;
//   }
// }
// 
// Path: src/main/java/jocket/wait/WaitStrategy.java
// public interface WaitStrategy {
// 
//   /**
//    * Pauses for some time.
//    * @param seq TODO
//    */
//   void pauseWhile(int seq);
// 
//   /**
//    * Resets the strategy. Called when data has been read or written
//    * successfully.
//    */
//   void reset();
// 
// }


import java.io.OutputStream;
import jocket.wait.BusyYieldSleep;
import jocket.wait.WaitStrategy;
package jocket.impl;



public class JocketOutputStream extends OutputStream {

  private final JocketWriter writer;
  private final WaitStrategy wait;

  public JocketOutputStream(JocketWriter writer, WaitStrategy wait) {
    this.writer = writer;
    this.wait = wait;
  }

  public JocketOutputStream(JocketWriter writer) {
    this(writer, new BusyYieldSleep());
  }

  @Override
  public void write(int b) {
    write(new byte[] { (byte) b }, 0, 1);
  }

  @Override
  public void write(byte[] b, int off, int len) {
    while (len > 0) {
      final int written = writer.write(b, off, len);
      len -= written;
// Path: src/main/java/jocket/wait/BusyYieldSleep.java
// public class BusyYieldSleep implements WaitStrategy {
// 
//   public static final int SPIN = 1000000;
// 
//   public static final int YIELD = SPIN + 1;
// 
//   public static final int SLEEP = YIELD + 1;
// 
//   private int counter;
// 
//   @Override
//   public void pauseWhile(int seq) {
//     int counter = this.counter++;
//     if (counter < SPIN)
//       return;
//     else if (counter < YIELD)
//       Thread.yield();
//     else if (counter < SLEEP)
//       LockSupport.parkNanos(1);
//     else {
//       this.counter = 0;
//     }
//   }
// 
//   @Override
//   public void reset() {
//     counter = 0;
//   }
// }
// 
// Path: src/main/java/jocket/wait/WaitStrategy.java
// public interface WaitStrategy {
// 
//   /**
//    * Pauses for some time.
//    * @param seq TODO
//    */
//   void pauseWhile(int seq);
// 
//   /**
//    * Resets the strategy. Called when data has been read or written
//    * successfully.
//    */
//   void reset();
// 
// }


// Path: src/main/java/jocket/impl/JocketOutputStream.java
import java.io.OutputStream;
import jocket.wait.BusyYieldSleep;
import jocket.wait.WaitStrategy;

package jocket.impl;



public class JocketOutputStream extends OutputStream {

  private final JocketWriter writer;
  private final WaitStrategy wait;

  public JocketOutputStream(JocketWriter writer, WaitStrategy wait) {
    this.writer = writer;
    this.wait = wait;
  }

  public JocketOutputStream(JocketWriter writer) {
    this(writer, new BusyYieldSleep());
  }

  @Override
  public void write(int b) {
    write(new byte[] { (byte) b }, 0, 1);
  }

  @Override
  public void write(byte[] b, int off, int len) {
    while (len > 0) {
      final int written = writer.write(b, off, len);
      len -= written;
      off += written;