// Path: src/main/java/com/healthmarketscience/rmiio/SimpleRemoteInputStream.java
// public class SimpleRemoteInputStream extends RemoteInputStreamServer
// {
//   private static final long serialVersionUID = 20080212L;
// 
//   /** manages reading from the given stream in a packet-like manner */
//   private transient final InputStreamAdapter _inAdapter;
// 
//   public SimpleRemoteInputStream(InputStream in) {
//     this(in, DUMMY_MONITOR, DEFAULT_CHUNK_SIZE);
//   }
// 
//   public SimpleRemoteInputStream(
//     InputStream in,
//     RemoteStreamMonitor<RemoteInputStreamServer> monitor) {
//     this(in, monitor, DEFAULT_CHUNK_SIZE);
//   }
// 
//   public SimpleRemoteInputStream(
//     InputStream in,
//     RemoteStreamMonitor<RemoteInputStreamServer> monitor,
//     int chunkSize)
//   {
//     super(in, monitor, chunkSize);
//     _inAdapter = InputStreamAdapter.create(in, _chunkSize);
//   }
// 
//   @Override
//   public boolean usingGZIPCompression()
//   {
//     // no compression
//     return false;
//   }
// 
//   @Override
//   protected int availableImpl()
//     throws IOException
//   {
//     synchronized(getLock()) {
//       return _in.available();
//     }
//   }
// 
//   @Override
//   protected byte[] readPacket()
//     throws IOException
//   {
//     // will be called synchronized
// 
//     // read another packet of data
//     byte[] packet = _inAdapter.readPacket();
//     if(packet != null) {
//       _monitor.localBytesMoved(this, packet.length);
//     }
//     return packet;
//   }
// 
//   @Override
//   protected long skip(long n)
//     throws IOException
//   {
//     // will be called synchronized
//     long numSkipped = _in.skip(n);
//     _monitor.localBytesSkipped(this, numSkipped);
//     return numSkipped;
//   }
// 
// }


import java.io.FileInputStream;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
/*
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 examples.iiop;



/**
 * Example corba client which sends a file (given on the command line) to the
 * example server using a RemoteInputStream.
 *
 * @author James Ahlborn
 */
public class TestClient {

  public static void main(String[] args) throws Exception
  {
    if(args.length < 1) {
      System.err.println("Usage: <file>");
      System.exit(1);
    }

    // grab the file name from the commandline
    String fileName = args[0];

    TestServer.CorbaExporter ce = new TestServer.CorbaExporter();
    
    // get a handle to the remote service to which we want to send the file
    Context ctx = new InitialContext();
    RemoteFileServer stub = (RemoteFileServer)
      PortableRemoteObject.narrow(
          ctx.lookup("RemoteFileServer"), RemoteFileServer.class);

    System.out.println("Sending file " + fileName);

    // setup the remote input stream.  note, the client here is actually
    // acting as an RMI server (very confusing, i know).  this code sets up an
    // RMI server in the client, which the RemoteFileServer will then
    // interact with to get the file data.
// Path: src/main/java/com/healthmarketscience/rmiio/SimpleRemoteInputStream.java
// public class SimpleRemoteInputStream extends RemoteInputStreamServer
// {
//   private static final long serialVersionUID = 20080212L;
// 
//   /** manages reading from the given stream in a packet-like manner */
//   private transient final InputStreamAdapter _inAdapter;
// 
//   public SimpleRemoteInputStream(InputStream in) {
//     this(in, DUMMY_MONITOR, DEFAULT_CHUNK_SIZE);
//   }
// 
//   public SimpleRemoteInputStream(
//     InputStream in,
//     RemoteStreamMonitor<RemoteInputStreamServer> monitor) {
//     this(in, monitor, DEFAULT_CHUNK_SIZE);
//   }
// 
//   public SimpleRemoteInputStream(
//     InputStream in,
//     RemoteStreamMonitor<RemoteInputStreamServer> monitor,
//     int chunkSize)
//   {
//     super(in, monitor, chunkSize);
//     _inAdapter = InputStreamAdapter.create(in, _chunkSize);
//   }
// 
//   @Override
//   public boolean usingGZIPCompression()
//   {
//     // no compression
//     return false;
//   }
// 
//   @Override
//   protected int availableImpl()
//     throws IOException
//   {
//     synchronized(getLock()) {
//       return _in.available();
//     }
//   }
// 
//   @Override
//   protected byte[] readPacket()
//     throws IOException
//   {
//     // will be called synchronized
// 
//     // read another packet of data
//     byte[] packet = _inAdapter.readPacket();
//     if(packet != null) {
//       _monitor.localBytesMoved(this, packet.length);
//     }
//     return packet;
//   }
// 
//   @Override
//   protected long skip(long n)
//     throws IOException
//   {
//     // will be called synchronized
//     long numSkipped = _in.skip(n);
//     _monitor.localBytesSkipped(this, numSkipped);
//     return numSkipped;
//   }
// 
// }


// Path: src/corbaExample/src/java/examples/iiop/TestClient.java
import java.io.FileInputStream;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.healthmarketscience.rmiio.SimpleRemoteInputStream;

/*
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 examples.iiop;



/**
 * Example corba client which sends a file (given on the command line) to the
 * example server using a RemoteInputStream.
 *
 * @author James Ahlborn
 */
public class TestClient {

  public static void main(String[] args) throws Exception
  {
    if(args.length < 1) {
      System.err.println("Usage: <file>");
      System.exit(1);
    }

    // grab the file name from the commandline
    String fileName = args[0];

    TestServer.CorbaExporter ce = new TestServer.CorbaExporter();
    
    // get a handle to the remote service to which we want to send the file
    Context ctx = new InitialContext();
    RemoteFileServer stub = (RemoteFileServer)
      PortableRemoteObject.narrow(
          ctx.lookup("RemoteFileServer"), RemoteFileServer.class);

    System.out.println("Sending file " + fileName);

    // setup the remote input stream.  note, the client here is actually
    // acting as an RMI server (very confusing, i know).  this code sets up an
    // RMI server in the client, which the RemoteFileServer will then
    // interact with to get the file data.
    SimpleRemoteInputStream istream = new SimpleRemoteInputStream(