提交 71603295 authored 作者: Thomas Mueller's avatar Thomas Mueller

Use a RuntimeException for UnsupportedEncoding

上级 152e4944
......@@ -507,7 +507,7 @@ public class ScriptCommand extends ScriptBase {
return prep.executeQuery();
}
private void reset() throws SQLException {
private void reset() {
result = null;
buffer = null;
lineSeparator = StringUtils.utf8Encode(SysProperties.LINE_SEPARATOR);
......
......@@ -9,17 +9,14 @@ package org.h2.server.web;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.h2.util.New;
import org.h2.util.StringUtils;
......@@ -127,20 +124,12 @@ public class WebServlet extends HttpServlet {
bytes = server.getFile(file);
if (bytes == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
try {
bytes = StringUtils.utf8Encode("File not found: " + file);
} catch (SQLException e) {
server.traceError(e);
}
} else {
if (session != null && file.endsWith(".jsp")) {
String page = StringUtils.utf8Decode(bytes);
page = PageParser.parse(page, session.map);
try {
bytes = StringUtils.utf8Encode(page);
} catch (SQLException e) {
server.traceError(e);
}
}
resp.setContentType(mimeType);
if (!cache) {
......
......@@ -196,8 +196,6 @@ class WebThread extends Thread implements DatabaseEventListener {
}
} catch (IOException e) {
TraceSystem.traceThrowable(e);
} catch (SQLException e) {
TraceSystem.traceThrowable(e);
}
IOUtils.closeSilently(output);
IOUtils.closeSilently(input);
......@@ -210,7 +208,7 @@ class WebThread extends Thread implements DatabaseEventListener {
}
}
private boolean process() throws IOException, SQLException {
private boolean process() throws IOException {
boolean keepAlive = false;
String head = readHeaderLine();
if (head.startsWith("GET ") || head.startsWith("POST ")) {
......@@ -254,11 +252,7 @@ class WebThread extends Thread implements DatabaseEventListener {
if (session != null && file.endsWith(".jsp")) {
String page = StringUtils.utf8Decode(bytes);
page = PageParser.parse(page, session.map);
try {
bytes = StringUtils.utf8Encode(page);
} catch (SQLException e) {
server.traceError(e);
}
}
message = "HTTP/1.1 200 OK\n";
message += "Content-Type: " + mimeType + "\n";
......
......@@ -21,7 +21,6 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
......@@ -345,12 +344,12 @@ public class IOUtils {
* @param in the input stream or null
* @return the reader
*/
public static Reader getReader(InputStream in) throws SQLException {
public static Reader getReader(InputStream in) {
try {
// InputStreamReader may read some more bytes
return in == null ? null : new BufferedReader(new InputStreamReader(in, Constants.UTF8));
} catch (UnsupportedEncodingException e) {
throw Message.convert(e);
throw Message.convertToInternal(e);
}
}
......@@ -361,11 +360,11 @@ public class IOUtils {
* @param out the output stream or null
* @return the writer
*/
public static Writer getWriter(OutputStream out) throws SQLException {
public static Writer getWriter(OutputStream out) {
try {
return out == null ? null : new BufferedWriter(new OutputStreamWriter(out, Constants.UTF8));
} catch (UnsupportedEncodingException e) {
throw Message.convert(e);
throw Message.convertToInternal(e);
}
}
......@@ -377,7 +376,7 @@ public class IOUtils {
* @param s the string
* @return the input stream
*/
public static InputStream getInputStream(String s) throws SQLException {
public static InputStream getInputStream(String s) {
if (s == null) {
return null;
}
......@@ -402,11 +401,11 @@ public class IOUtils {
* @param in the input stream
* @return the reader
*/
public static Reader getAsciiReader(InputStream in) throws SQLException {
public static Reader getAsciiReader(InputStream in) {
try {
return in == null ? null : new InputStreamReader(in, "US-ASCII");
} catch (UnsupportedEncodingException e) {
throw Message.convert(e);
throw Message.convertToInternal(e);
}
}
......
......@@ -276,11 +276,11 @@ public class StringUtils {
* @param s the text
* @return the UTF-8 representation
*/
public static byte[] utf8Encode(String s) throws SQLException {
public static byte[] utf8Encode(String s) {
try {
return s.getBytes(Constants.UTF8);
} catch (UnsupportedEncodingException e) {
throw Message.convert(e);
throw Message.convertToInternal(e);
}
}
......@@ -390,8 +390,7 @@ public class StringUtils {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return s;
throw Message.convertToInternal(e);
}
//## Java 1.4 end ##
/*## Java 1.3 only begin ##
......
......@@ -14,8 +14,6 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.sql.SQLException;
import org.h2.engine.Constants;
import org.h2.message.Message;
......@@ -33,14 +31,14 @@ public class ReaderInputStream extends InputStream {
private int remaining;
private byte[] buffer;
public ReaderInputStream(Reader reader) throws SQLException {
public ReaderInputStream(Reader reader) {
chars = new char[Constants.IO_BUFFER_SIZE];
this.reader = reader;
out = new ByteArrayOutputStream(Constants.IO_BUFFER_SIZE);
try {
writer = new BufferedWriter(new OutputStreamWriter(out, Constants.UTF8));
} catch (UnsupportedEncodingException e) {
throw Message.convert(e);
throw Message.convertToInternal(e);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论