mcharsetconverter.java

来自「httptunnel.jar httptunnel java 源码」· Java 代码 · 共 52 行

JAVA
52
字号
package net.jumperz.app.MGuardian.plugin;

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

public class MCharsetConverter
extends MGuardianPlugin
{
//net.umperz....MCharsetConverter EUC_JP Shift_JIS
//--------------------------------------------------------------------------------
public Map execute( Map sessionInfo )
{
MHttpResponse response = ( MHttpResponse )sessionInfo.get( "response" );
if( response == null )
	{
	Exception e = new Exception( "Configuration Error. You need to call this plugin from 'RESPONSE-TYPE' rule like 'type=responseHeader'." );
	e.printStackTrace();
	return null;
	}

String arg = ( String )sessionInfo.get( "arg" );
String[] array = arg.split( "[ \\t]{1,}" );
if( array.length != 2 )
	{
	Exception e = new Exception( "Plugin Argument Error." );
	e.printStackTrace();
	return null;	
	}

String charFrom = array[ 0 ];
String charTo = array[ 1 ];

try
	{
	response.chunkToNormal();
	String bodyStr = response.getBodyAsString();
	bodyStr = MStringUtil.convertCharset( bodyStr, charFrom, charTo );
	response.setBody( bodyStr );
	response.setHeaderValue( "Content-Length", Integer.toString( bodyStr.length() ) );
	}
catch( IOException e )
	{
	e.printStackTrace();
	return null;
	}

return null;
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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