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

org.kernelab.basis.io.SocketKit Maven / Gradle / Ivy

There is a newer version: 0.0.19-RELEASE
Show newest version
package org.kernelab.basis.io;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class SocketKit
{
	private Socket	socket;

	public SocketKit()
	{
		this(null);
	}

	public SocketKit(Socket socket)
	{
		this.setSocket(socket);
	}

	public Socket getSocket()
	{
		return socket;
	}

	@SuppressWarnings("unchecked")
	public  T readObject() throws IOException
	{
		T object = null;

		ObjectInputStream objectReader = new ObjectInputStream(this.getSocket().getInputStream());

		try
		{
			object = (T) objectReader.readObject();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}

		return object;
	}

	public void sendObject(Object object) throws IOException
	{
		ObjectOutputStream objectSender = new ObjectOutputStream(this.getSocket().getOutputStream());

		objectSender.writeObject(object);
	}

	public void setSocket(Socket socket)
	{
		this.socket = socket;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy