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

Use a RuntimeException for UnsupportedEncoding

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