当前位置: 首页>>代码示例>>Java>>正文


Java B2CConverter.getCharset方法代码示例

本文整理汇总了Java中org.apache.tomcat.util.buf.B2CConverter.getCharset方法的典型用法代码示例。如果您正苦于以下问题:Java B2CConverter.getCharset方法的具体用法?Java B2CConverter.getCharset怎么用?Java B2CConverter.getCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tomcat.util.buf.B2CConverter的用法示例。


在下文中一共展示了B2CConverter.getCharset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader) {
        return;
    }

    // Ensure that the specified encoding is valid
    byte buffer[] = new byte[1];
    buffer[0] = (byte) 'a';

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);

    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:31,代码来源:Request.java

示例2: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader)
        return;
    
    // Ensure that the specified encoding is valid
    byte buffer[] = new byte[1];
    buffer[0] = (byte) 'a';

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);
    
    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:30,代码来源:Request.java

示例3: getFileText

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
@Override
public String getFileText(String originalPath, boolean virtual) throws IOException {
	try {
		ServletContextAndPath csAndP = getServletContextAndPath(originalPath, virtual);
		ServletContext context = csAndP.getServletContext();
		String path = csAndP.getPath();
		RequestDispatcher rd = context.getRequestDispatcher(path);
		if (rd == null) {
			throw new IOException("Couldn't get request dispatcher for path: " + path);
		}
		ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
		ResponseIncludeWrapper responseIncludeWrapper = new ResponseIncludeWrapper(context, req, res, basos);
		rd.include(req, responseIncludeWrapper);
		// We can't assume the included servlet flushed its output
		responseIncludeWrapper.flushOutputStreamOrWriter();
		byte[] bytes = basos.toByteArray();

		// Assume platform default encoding unless otherwise specified
		String retVal;
		if (inputEncoding == null) {
			retVal = new String(bytes);
		} else {
			retVal = new String(bytes, B2CConverter.getCharset(inputEncoding));
		}

		// make an assumption that an empty response is a failure. This is
		// a problem
		// if a truly empty file
		// were included, but not sure how else to tell.
		if (retVal.equals("") && !req.getMethod().equalsIgnoreCase(org.apache.coyote.http11.Constants.HEAD)) {
			throw new IOException("Couldn't find file: " + path);
		}
		return retVal;
	} catch (ServletException e) {
		throw new IOException(
				"Couldn't include file: " + originalPath + " because of ServletException: " + e.getMessage());
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:39,代码来源:SSIServletExternalResolver.java

示例4: open

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Open the new log file for the date specified by <code>dateStamp</code>.
 */
protected synchronized void open() {
    // Open the current log file
    // If no rotate - no need for dateStamp in fileName
    File pathname = getLogFile(rotatable && !renameOnRotate);

    Charset charset = null;
    if (encoding != null) {
        try {
            charset = B2CConverter.getCharset(encoding);
        } catch (UnsupportedEncodingException ex) {
            log.error(sm.getString(
                    "accessLogValve.unsupportedEncoding", encoding), ex);
        }
    }
    if (charset == null) {
        charset = Charset.defaultCharset();
    }

    try {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(pathname, true), charset), 128000),
                false);

        currentLogFile = pathname;
    } catch (IOException e) {
        writer = null;
        currentLogFile = null;
        log.error(sm.getString("accessLogValve.openFail", pathname), e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:34,代码来源:AccessLogValve.java

示例5: getDigestCharset

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
protected Charset getDigestCharset() throws UnsupportedEncodingException {
    if (digestEncoding == null) {
        return Charset.defaultCharset();
    } else {
        return B2CConverter.getCharset(getDigestEncoding());
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:RealmBase.java

示例6: URLDecode

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Decode and return the specified URL-encoded byte array.
 *
 * @param bytes The url-encoded byte array
 * @param enc The encoding to use; if null, the default encoding is used. If
 * an unsupported encoding is specified null will be returned
 * @param isQuery Is this a query string being processed
 * @exception IllegalArgumentException if a '%' character is not followed
 * by a valid 2-digit hexadecimal number
 */
public static String URLDecode(byte[] bytes, String enc, boolean isQuery) {

    if (bytes == null)
        return null;

    int len = bytes.length;
    int ix = 0;
    int ox = 0;
    while (ix < len) {
        byte b = bytes[ix++];     // Get byte to test
        if (b == '+' && isQuery) {
            b = (byte)' ';
        } else if (b == '%') {
            if (ix + 2 > len) {
                throw new IllegalArgumentException(
                        sm.getString("requestUtil.urlDecode.missingDigit"));
            }
            b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
                        + convertHexDigit(bytes[ix++]));
        }
        bytes[ox++] = b;
    }
    if (enc != null) {
        try {
            return new String(bytes, 0, ox, B2CConverter.getCharset(enc));
        } catch (UnsupportedEncodingException uee) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("requestUtil.urlDecode.uee", enc), uee);
            }
            return null;
        }
    }
    return new String(bytes, 0, ox);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:RequestUtil.java

示例7: getCharset

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
private Charset getCharset(String encoding) {
    if (encoding == null) {
        return DEFAULT_CHARSET;
    }
    try {
        return B2CConverter.getCharset(encoding);
    } catch (UnsupportedEncodingException e) {
        return DEFAULT_CHARSET;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:11,代码来源:Parameters.java

示例8: doCreateString

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
private long doCreateString(String input, int size,
        boolean defensiveCopyWorkAround) {
    int loops = 10000;
    byte[] inputBytes = input.getBytes();
    byte[] bytes = new byte[size];
    int inputLength = inputBytes.length;

    System.arraycopy(inputBytes, 0, bytes, 0, inputLength);

    String[] result = new String[loops];
    Charset charset = null;
    try {
        charset = B2CConverter.getCharset("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    long start = System.nanoTime();
    for (int i = 0; i < loops; i++) {
        if (defensiveCopyWorkAround) {
            byte[] tmp = new byte[inputLength];
            System.arraycopy(bytes, 0, tmp, 0, inputLength);
            result[i] = new String(tmp, 0, inputLength, charset);
        } else {
            result[i] = new String(bytes, 0, inputLength, charset);
        }
    }

    return System.nanoTime() - start;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:32,代码来源:TesterParametersPerformance.java

示例9: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of
 * this request.  This method must be called prior to reading request
 * parameters or reading input using <code>getReader()</code>.
 *
 * @param enc The character encoding to be used
 *
 * @exception UnsupportedEncodingException if the specified encoding
 *  is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException {

    if (usingReader) {
        return;
    }

    // Confirm that the encoding name is valid
    B2CConverter.getCharset(enc);

    // Save the validated encoding
    coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:27,代码来源:Request.java

示例10: getCharset

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
private Charset getCharset(String encoding) {
	if (encoding == null) {
		return DEFAULT_CHARSET;
	}
	try {
		return B2CConverter.getCharset(encoding);
	} catch (UnsupportedEncodingException e) {
		return DEFAULT_CHARSET;
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:11,代码来源:Parameters.java

示例11: setCharacterEncoding

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Overrides the name of the character encoding used in the body of this
 * request. This method must be called prior to reading request parameters
 * or reading input using <code>getReader()</code>.
 *
 * @param enc
 *            The character encoding to be used
 *
 * @exception UnsupportedEncodingException
 *                if the specified encoding is not supported
 *
 * @since Servlet 2.3
 */
@Override
public void setCharacterEncoding(String enc) throws UnsupportedEncodingException {

	if (usingReader) {
		return;
	}

	// Confirm that the encoding name is valid
	B2CConverter.getCharset(enc);

	// Save the validated encoding
	coyoteRequest.setCharacterEncoding(enc);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:Request.java

示例12: open

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Open the new log file for the date specified by <code>dateStamp</code>.
 */
protected synchronized void open() {
	// Open the current log file
	// If no rotate - no need for dateStamp in fileName
	File pathname = getLogFile(rotatable && !renameOnRotate);

	Charset charset = null;
	if (encoding != null) {
		try {
			charset = B2CConverter.getCharset(encoding);
		} catch (UnsupportedEncodingException ex) {
			log.error(sm.getString("accessLogValve.unsupportedEncoding", encoding), ex);
		}
	}
	if (charset == null) {
		charset = Charset.defaultCharset();
	}

	try {
		writer = new PrintWriter(
				new BufferedWriter(new OutputStreamWriter(new FileOutputStream(pathname, true), charset), 128000),
				false);

		currentLogFile = pathname;
	} catch (IOException e) {
		writer = null;
		currentLogFile = null;
		log.error(sm.getString("accessLogValve.openFail", pathname), e);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:AccessLogValve.java

示例13: getFileText

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
@Override
public String getFileText(String originalPath, boolean virtual)
        throws IOException {
    try {
        ServletContextAndPath csAndP = getServletContextAndPath(
                originalPath, virtual);
        ServletContext context = csAndP.getServletContext();
        String path = csAndP.getPath();
        RequestDispatcher rd = context.getRequestDispatcher(path);
        if (rd == null) {
            throw new IOException(
                    "Couldn't get request dispatcher for path: " + path);
        }
        ByteArrayServletOutputStream basos =
            new ByteArrayServletOutputStream();
        ResponseIncludeWrapper responseIncludeWrapper =
            new ResponseIncludeWrapper(context, req, res, basos);
        rd.include(req, responseIncludeWrapper);
        //We can't assume the included servlet flushed its output
        responseIncludeWrapper.flushOutputStreamOrWriter();
        byte[] bytes = basos.toByteArray();

        //Assume platform default encoding unless otherwise specified
        String retVal;
        if (inputEncoding == null) {
            retVal = new String( bytes );
        } else {
            retVal = new String (bytes,
                    B2CConverter.getCharset(inputEncoding));
        }

        //make an assumption that an empty response is a failure. This is
        // a problem
        // if a truly empty file
        //were included, but not sure how else to tell.
        if (retVal.equals("") && !req.getMethod().equalsIgnoreCase(
                org.apache.coyote.http11.Constants.HEAD)) {
            throw new IOException("Couldn't find file: " + path);
        }
        return retVal;
    } catch (ServletException e) {
        throw new IOException("Couldn't include file: " + originalPath
                + " because of ServletException: " + e.getMessage());
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:SSIServletExternalResolver.java

示例14: parseParameters

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
/**
 * Append request parameters from the specified String to the specified Map.
 * It is presumed that the specified Map is not accessed from any other
 * thread, so no synchronization is performed.
 * <p>
 * <strong>IMPLEMENTATION NOTE</strong>: URL decoding is performed
 * individually on the parsed name and value elements, rather than on the
 * entire query string ahead of time, to properly deal with the case where
 * the name or value includes an encoded "=" or "&" character that would
 * otherwise be interpreted as a delimiter.
 *
 * NOTE: byte array data is modified by this method. Caller beware.
 *
 * @param map
 *            Map that accumulates the resulting parameters
 * @param data
 *            Input string containing request parameters
 * @param encoding
 *            The encoding to use; if null, the default encoding is used
 *
 * @exception UnsupportedEncodingException
 *                if the requested encoding is not supported.
 */
public static void parseParameters(Map<String, String[]> map, byte[] data, String encoding)
		throws UnsupportedEncodingException {

	Charset charset = B2CConverter.getCharset(encoding);

	if (data != null && data.length > 0) {
		int ix = 0;
		int ox = 0;
		String key = null;
		String value = null;
		while (ix < data.length) {
			byte c = data[ix++];
			switch ((char) c) {
			case '&':
				value = new String(data, 0, ox, charset);
				if (key != null) {
					putMapEntry(map, key, value);
					key = null;
				}
				ox = 0;
				break;
			case '=':
				if (key == null) {
					key = new String(data, 0, ox, charset);
					ox = 0;
				} else {
					data[ox++] = c;
				}
				break;
			case '+':
				data[ox++] = (byte) ' ';
				break;
			case '%':
				data[ox++] = (byte) ((convertHexDigit(data[ix++]) << 4) + convertHexDigit(data[ix++]));
				break;
			default:
				data[ox++] = c;
			}
		}
		// The last value does not end in '&'. So save it now.
		if (key != null) {
			value = new String(data, 0, ox, charset);
			putMapEntry(map, key, value);
		}
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:71,代码来源:RequestUtil.java

示例15: testCreateString

import org.apache.tomcat.util.buf.B2CConverter; //导入方法依赖的package包/类
@Test
public void testCreateString() throws UnsupportedEncodingException {
    B2CConverter.getCharset("ISO-8859-1");
    doCreateStringMultiple("foo");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:6,代码来源:TesterParametersPerformance.java


注:本文中的org.apache.tomcat.util.buf.B2CConverter.getCharset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。