このアーカイブは同期化されません。 mixi の日記が更新されても、このアーカイブには反映されません。
更新領域は UpdateRectangle クラスとして表す。
UpdateRectangle も Message を実装させることで、
RFB(In|Out)putputStream から直接読み書きが可能となる。
========== UpdateRectangle.java ==========
package jp.loafer.rfb.message;
import java.io.IOException;
import jp.loafer.rfb.RFBContext;
import jp.loafer.rfb.io.RFBInputStream;
import jp.loafer.rfb.io.RFBOutputStream;
/**
* 更新領域を表すクラス。
* @author kes
*/
public class UpdateRectangle implements Message {
/**
* 永続化用既定コンストラクタ。
*/
public UpdateRectangle() {
//
}
/**
* 更新領域を作成。
* @param x X 座標。
* @param y Y 座標。
* @param width 幅。
* @param height 高さ。
* @param encodingType 符号化方式。
* @param data 符号化された画素データ。
*/
public UpdateRectangle(int x, int y, int width, int height,
int encodingType, byte[] data) {
if (x < 0 || y < 0)
throw new IllegalArgumentException("Invalid location.");
if (width <= 0 || height <= 0)
throw new IllegalArgumentException("Invalid size.");
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.encodingType = encodingType;
this.data = data;
}
/**
* 左上の X 座標を取得。
* @return 左上の X 座標。
*/
public int getX() {
return x;
}
/**
* 左上の Y 座標を取得。
* @return 左上の Y 座標。
*/
public int getY() {
return y;
}
/**
* 幅を取得。
* @return 幅。
*/
public int getWidth() {
return width;
}
/**
* 高さを取得。
* @return 高さ。
*/
public int getHeight() {
return height;
}
/**
* 符号化方式を取得。
* @return 符号化方式。
*/
public int getEncodingType() {
return encodingType;
}
/**
* 符号化された画素データを取得。
* @return 符号化された画素データ。
*/
public byte[] getData() {
return data;
}
/**
* @see Message#read(RFBContext, RFBInputStream)
*/
public void read(RFBContext context, RFBInputStream in) throws IOException {
// 未実装
throw new UnsupportedOperationException();
}
/**
* @see Message#write(RFBContext, RFBOutputStream)
*/
public void write(RFBContext context, RFBOutputStream out) throws IOException {
out.writeU16(x);
out.writeU16(y);
out.writeU16(width);
out.writeU16(height);
out.writeS32(encodingType);
out.write(data);
}
private int x;
private int y;
private int width;
private int height;
private int encodingType;
private byte[] data;
}
========== end of UpdateRectangle.java ==========
最初は、UpdateRectangle を抽象クラスとして、
符号化に応じた具象クラスを量産することを考えたのだが、
結局それはやめ、データを配列で持たせて汎用とした。
UpdateRectangle はあくまでも Message である。
Message はストリームを流れるデータそのままの表現であり、
そこに符号化等の処理が含まれると変だと感じたからだ。
なので、画素データのメッセージの符号化は、
UpdateRectangle を作成・利用する側で行うことにし、
UpdateRectangle 自身にはロジックを組み込まない。