All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.razorvine.pyro.IOUtil Maven / Gradle / Ivy

Go to download

This library allows your Java program to interface very easily with the Python world. It uses the Pyro protocol to call methods on remote objects. (See https://pyro5.readthedocs.io/). Pyrolite only implements part of the client side Pyro library, hence its name 'lite'... So if you don't need Pyro's full feature set, Pyrolite may be a good choice to connect java or .NET and python. Version 5.0 changes: support Pyro5 wire protocol. Dropped support of Pyro4 (stick to version 4.xx for that).

There is a newer version: 5.1
Show newest version
package net.razorvine.pyro;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Lowlevel I/O utilities.
 * 
 * @author Irmen de Jong ([email protected])
 */
class IOUtil
{
	/**
	 * send a message to the outputstream.
	 */
	public static void send(OutputStream out, byte[] message) throws IOException {
		out.write(message);
	}

	/**
	 * Receive a message of the given size from the inputstream.
	 * Makes sure the complete message is received, raises IOException otherwise.
	 */
	public static byte[] recv(InputStream in, int size) throws IOException {
		byte [] bytes = new byte [size];
		int numRead = in.read(bytes);
		if(numRead==-1) {
			throw new IOException("premature end of data");
		}
		while (numRead < size) {
		  int len = in.read(bytes, numRead, size - numRead);
		  if(len==-1) {
			  throw new IOException("premature end of data");
		  }
		  numRead+=len;
		}
		return bytes;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy