ca.odell.glazedlists.impl.ctp.SendChunk Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glazedlists_java15 Show documentation
Show all versions of glazedlists_java15 Show documentation
Event-driven lists for dynamically filtered and sorted tables
/* Glazed Lists (c) 2003-2006 */
/* http://publicobject.com/glazedlists/ publicobject.com,*/
/* O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.ctp;
// NIO is used for CTP
import ca.odell.glazedlists.impl.nio.*;
import java.util.*;
import java.nio.*;
import java.nio.channels.*;
import java.net.*;
import java.io.*;
import ca.odell.glazedlists.impl.io.Bufferlo;
// logging
import java.util.logging.*;
/**
* Sends a chunk of data on the NIO thread.
*
* @author Jesse Wilson
*/
class SendChunk implements Runnable {
/** the destination */
private CTPConnection connection;
/** the content */
private Bufferlo data;
/**
* Create a new SendChunk.
*/
public SendChunk(CTPConnection connection, Bufferlo data) {
this.connection = connection;
this.data = data;
}
/**
* Writes the data.
*/
public void run() {
if(connection.state != CTPConnection.STATE_READY) throw new IllegalStateException();
try {
// calculate the total bytes remaining
int totalRemaining = (data != null) ? data.length() : 0;
// write the chunk
String chunkSizeInHex = Integer.toString(totalRemaining, 16);
connection.writer.write(chunkSizeInHex);
connection.writer.write("\r\n");
if(data != null) connection.writer.append(data);
connection.writer.write("\r\n");
connection.writer.writeToChannel(connection.socketChannel, connection.selectionKey);
} catch(IOException e) {
connection.close(e);
}
}
}