// Path: src/main/java/com/healthmarketscience/rmiio/PacketOutputStream.java
// public abstract class PacketOutputStream extends OutputStream
// {
// 
//   public PacketOutputStream() {
//   }
// 
//   /**
//    * Puts the given "packet" into the output stream.  The packet should be
//    * filled with data.  The caller is giving control of the buffer to the
//    * PacketOutputStream, and therefore should not attempt to use the byte[]
//    * again.
//    *
//    * @param packet fully filled array of bytes to give to the OutputStream
//    */
//   public abstract void writePacket(byte[] packet)
//     throws IOException;
// 
// }


import java.io.IOException;
import java.io.OutputStream;
import com.healthmarketscience.rmiio.PacketOutputStream;
/*
Copyright (c) 2007 Health Market Science, Inc.

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 com.healthmarketscience.rmiio.util;




/**
 * Utility class for optimizing different write strategies based on the type
 * of the underlying OutputStream.
 *
 * @author James Ahlborn
 */
public abstract class OutputStreamAdapter
{

  private OutputStreamAdapter() {
  }

  /**
   * @return the underlying OutputStream
   */
  public abstract OutputStream getOutputStream();

  /**
   * Puts the given "packet" into the output stream.  The packet should be
   * filled with data.  The caller is giving control of the buffer to the
   * PacketOutputStream, and therefore should not attempt to use the byte[]
   * again.
   *
   * @param packet fully filled array of bytes to give to the OutputStream
   */
  public abstract void writePacket(byte[] packet) throws IOException;

  /**
   * @param istream stream to wrap and for which the implementation is
   *                optimized
   * @return an OutputStreamAdapter optimized for the stream type
   */
  public static OutputStreamAdapter create(
      OutputStream istream)
  {
// Path: src/main/java/com/healthmarketscience/rmiio/PacketOutputStream.java
// public abstract class PacketOutputStream extends OutputStream
// {
// 
//   public PacketOutputStream() {
//   }
// 
//   /**
//    * Puts the given "packet" into the output stream.  The packet should be
//    * filled with data.  The caller is giving control of the buffer to the
//    * PacketOutputStream, and therefore should not attempt to use the byte[]
//    * again.
//    *
//    * @param packet fully filled array of bytes to give to the OutputStream
//    */
//   public abstract void writePacket(byte[] packet)
//     throws IOException;
// 
// }


// Path: src/main/java/com/healthmarketscience/rmiio/util/OutputStreamAdapter.java
import java.io.IOException;
import java.io.OutputStream;
import com.healthmarketscience.rmiio.PacketOutputStream;

/*
Copyright (c) 2007 Health Market Science, Inc.

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 com.healthmarketscience.rmiio.util;




/**
 * Utility class for optimizing different write strategies based on the type
 * of the underlying OutputStream.
 *
 * @author James Ahlborn
 */
public abstract class OutputStreamAdapter
{

  private OutputStreamAdapter() {
  }

  /**
   * @return the underlying OutputStream
   */
  public abstract OutputStream getOutputStream();

  /**
   * Puts the given "packet" into the output stream.  The packet should be
   * filled with data.  The caller is giving control of the buffer to the
   * PacketOutputStream, and therefore should not attempt to use the byte[]
   * again.
   *
   * @param packet fully filled array of bytes to give to the OutputStream
   */
  public abstract void writePacket(byte[] packet) throws IOException;

  /**
   * @param istream stream to wrap and for which the implementation is
   *                optimized
   * @return an OutputStreamAdapter optimized for the stream type
   */
  public static OutputStreamAdapter create(
      OutputStream istream)
  {
    if(istream instanceof PacketOutputStream) {