📄 connectioner.java
字号:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.Image;
public class Connectioner implements Runnable {
private HttpConnection con;
private DataOutputStream os;
private final String URL="http://localhost:8080/photoServer/createImage/";
private Image image;
MainLet midplet;
/**
*
*/
public Connectioner(MainLet midplet) {
super();
this.midplet=midplet;
new Thread(this).start();
}
public void run(){
connHttp();
}
/*
public synchronized void connHttp(){
while(true){
System.out.println("httpconn wait now");
if((midplet.getIsSending())){
System.out.println("search");
try{
con=(HttpConnection)Connector.open(URL);
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("If-Modified-Since",
"29 Oct 1999 19:43:31 GMT");
con.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
con.setRequestProperty("Content-Language", "en-US");
os=new DataOutputStream(con.openOutputStream());
int[] rgbArg=new int[100*100];
midplet.getImage().getRGB(rgbArg,0,100,0,0,100,100);
for(int i=0;i<rgbArg.length;i++){
os.write(rgbArg[i]);
}
os.flush();
}catch(Exception e){
System.out.println("conn err");
e.printStackTrace();
}finally{
if(os!=null){
try{
os.close();
midplet.setIsSending(false);
midplet.setIsSend(true);
}catch(IOException ioe){};
}
}
midplet.setIsSending(false);
midplet.setIsSend(true);
}
try{
wait();
}catch(Exception e){
System.out.println("wait exception");
e.printStackTrace();
}
}
}
public synchronized void wakeUP(){
notifyAll();
}*/
public synchronized void connHttp(){
while(true){
System.out.println("httpconn wait now");
if((midplet.getIsSending())){
System.out.println("search");
try{
con=(HttpConnection)Connector.open(URL);
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("If-Modified-Since",
"29 Oct 1999 19:43:31 GMT");
con.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.0");
con.setRequestProperty("Content-Language", "en-US");
os=new DataOutputStream(con.openOutputStream());
int[] rgbArg=new int[100*100];
midplet.getImage().getRGB(rgbArg,0,100,0,0,100,100);
byte[] bytes=intTobyte(rgbArg);
os.write(bytes);
/*
for(int i=0;i<rgbArg.length;i++){
os.writeInt(rgbArg[i]);
System.out.println(rgbArg[i]);
}*/
os.flush();
}catch(Exception e){
System.out.println("conn err");
e.printStackTrace();
}finally{
if(os!=null){
try{
os.close();
midplet.setIsSending(false);
midplet.setIsSend(true);
}catch(IOException ioe){};
}
}
midplet.setIsSending(false);
midplet.setIsSend(true);
}
try{
wait();
}catch(Exception e){
System.out.println("wait exception");
e.printStackTrace();
}
}
}
public synchronized void wakeUP(){
notifyAll();
}
private byte[] intTobyte(int[] ints){
byte[] bytes=new byte[ints.length*4];
for(int i=0;i<ints.length;i++){
bytes[i*4]=(byte)(0xff&(ints[i]>>24));
bytes[i*4+1]=(byte)(0xff&(ints[i]>>16));
bytes[i*4+2]=(byte)(0xff&(ints[i]>>8));
bytes[i*4+3]=(byte)(0xff&(ints[i]>>0));
// byte []tmp = new byte[4];
// tmp[0] = (byte)(0xff&(data>>24));
// tmp[1] = (byte)(0xff&(data>>16));
// tmp[2] = (byte)(0xff&(data>> 8));
// tmp[3] = (byte)(0xff&(data>> 0));
if(i<100){
System.out.println(ints[i]);
}
}
return bytes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -