⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtunneldata.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
字号:
package net.jumperz.app.httptunnel;

import java.io.*;
import net.jumperz.util.*;

public final class MTunnelData
{
private int method;
private String sessionName;
private int sequence;
private byte[] buffer;

public static final int OPEN	= 0;
public static final int SEND	= 1;
public static final int CLOSE	= 2;
public static final int NOOP	= 3;
private static final int BUFSIZE = 1024;
//---------------------------------------------------------------------------------------
public MTunnelData()
{
method = NOOP;
sessionName = MStringUtil.generateRandomString();
sequence = 0;
buffer = "".getBytes();
}
//---------------------------------------------------------------------------------------
public MTunnelData( byte[] body )
throws IOException
{
ByteArrayInputStream bufStream = new ByteArrayInputStream( body );
BufferedReader reader = new BufferedReader( new InputStreamReader( bufStream, MCharset.CS_ISO_8859_1 ) );

int headerLength = 0;
String line	= null;

	//SessionName
line = reader.readLine();
headerLength += line.length() + 2;
sessionName = line;

	//Sequence
line = reader.readLine();
headerLength += line.length() + 2;
sequence = Integer.parseInt( line );

	//Method
line = reader.readLine();
headerLength += line.length() + 2;
method = Integer.parseInt( line );

	//Data
int bufferSize = body.length - headerLength;
buffer = new byte[ bufferSize ];
System.arraycopy( body, headerLength, buffer, 0, bufferSize );
}
//---------------------------------------------------------------------------------------
public final int getMethod()
{
return method;
}
//---------------------------------------------------------------------------------------
public final int getSequence()
{
return sequence;
}
//---------------------------------------------------------------------------------------
public final String getSessionName()
{
return sessionName;
}
//---------------------------------------------------------------------------------------
public final byte[] getBuffer()
{
return buffer;
}
//---------------------------------------------------------------------------------------
public final void setMethod( int IN_method )
{
method = IN_method;
}
//---------------------------------------------------------------------------------------
public final void setSequence( int in_sequence )
{
sequence = in_sequence;
}
//---------------------------------------------------------------------------------------
public final void setSessionName( String in_sessionName )
{
sessionName = in_sessionName;
}
//---------------------------------------------------------------------------------------
public final void setBuffer( byte[] in_buffer )
{
buffer = in_buffer;
}
//---------------------------------------------------------------------------------------
public final byte[] toByteArray()
{
StringBuffer strBuf = new StringBuffer( BUFSIZE );

	//SessionName
strBuf.append( sessionName );
strBuf.append( "\r\n" );

	//Sequence
strBuf.append( sequence );
strBuf.append( "\r\n" );

	//Method
strBuf.append( method );
strBuf.append( "\r\n" );

byte[] header = strBuf.toString().getBytes();
byte[] byteArray = new byte[ header.length + buffer.length ];
System.arraycopy( header, 0, byteArray, 0, header.length );
System.arraycopy( buffer, 0, byteArray, header.length, buffer.length );

return byteArray;
}
//---------------------------------------------------------------------------------------
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -