java的发布信息的代码 java的发布信息的代码是什么( 二 )


使其与原始消息一致 。
2.显式长度(Explicit length):在变长字段或消息前附加一个固定大小的字段,用来指示该字段或消息中包含了多少字节 。这种方法要确定消息长度的上限,以确定保存这个长度需要的字节数 。
接口:
Java代码import java.io.IOException;import java.io.OutputStream;public interface Framer {void frameMsg(byte [] message,OutputStream out) throws IOException;byte [] nextMsg() throws IOException;}
定界符的方式:
Java代码import java.io.ByteArrayOutputStream;import java.io.EOFException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;public class DelimFramer implements Framer {private InputStream in;//data source;private static final byte DELIMTER=(byte)'\n';//message delimiterpublic DelimFramer(InputStream in){this.in=in;}@Overridepublic void frameMsg(byte[] message, OutputStream out) throws IOException {//ensure that the message dose not contain the delimiterfor(byte b:message){if(b==DELIMTER)throw new IOException("Message contains delimiter");}out.write(message);out.write(DELIMTER);out.flush();}@Overridepublic byte[] nextMsg() throws IOException {ByteArrayOutputStream messageBuffer=new ByteArrayOutputStream();int nextByte;while((nextByte=in.read())!=DELIMTER){if(nextByte==-1){//end of stream?if(messageBuffer.size()==0){return null;}else{throw new EOFException("Non-empty message without delimiter");}}messageBuffer.write(nextByte);}return messageBuffer.toByteArray();}}
显式长度方法:
Java代码import java.io.DataInputStream;import java.io.EOFException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;public class LengthFramer implements Framer {public static final int MAXMESSAGELENGTH=65535;public static final int BYTEMASK=0xff;public static final int SHOTMASK=0xffff;public static final int BYTESHIFT=8;private DataInputStream in;// wrapper for data I/Opublic LengthFramer(InputStream in) throws IOException{this.in=new DataInputStream(in);}@Overridepublic void frameMsg(byte[] message, OutputStream out) throws IOException {if(message.lengthMAXMESSAGELENGTH){throw new IOException("message too long");}//write length prefixout.write((message.lengthBYTEMASK)BYTEMASK);out.write(message.lengthBYTEMASK);//write messageout.write(message);out.flush();}@Overridepublic byte[] nextMsg() throws IOException {int length;try{length=in.readUnsignedShort();}catch(EOFException e){//no (or 1 byte) message;return null;}//0=length=65535;byte [] msg=new byte[length];in.readFully(msg);//if exception,it's a framing error;return msg;}}
java写的系统如何发布到网上供人使用可以用tomcat服务器发布java的发布信息的代码,就像你自己用localhost访问一样java的发布信息的代码 , 别人访问是需要加上你的IP地址然后加上项目名之类的,组成url进行访问,这样的问题是你的ip暴露了,你可以在tomcat中配置一下
在Tomcat下面配置域名(如java的发布信息的代码:www.***.com)的时候,同时又不希望客户通过我们网站的IP或者域名访问到Tomcat默认的ROOT,配制方法如下:
1、打开Tomcat安装目录下的/conf/server.xml文件
2、在server.xml中将原有的Host name=“localhost“ appBase=“webapps“ ……修改为Host name=“您要配置的域名“ appBase=“webapps“……
3、在/conf/Catalina目录下建立目录“您要配置的域名的名称”,然后建立ROOT.xml文件,其格式和/conf/localhost目录下的ROOT.xml一致,但是内容如下:
?xml version='1.0' encoding='utf-8'?
Context displayName="Welcome to 56World!" docBase="D:/workplace/inbuilding" path=""
/Context
其中docBase中的内容就是你希望的打开您的域名(www.***.com) 的时候映射到的目录和默认的网页(如:index.jsp)
4、启动Tomcat服务器,就可以直接敲入域名访问你要访问的地址了 。
这个配置方法也是我查询的,具体没有试过,你可以试一下,希望可以帮到你

推荐阅读