Browse Source

Merge branch 'master' into jfinal-java8

James 8 years ago
parent
commit
76f3005530

+ 6 - 6
src/main/java/com/jfinal/render/FileRender.java

@@ -174,9 +174,9 @@ public class FileRender extends Render {
             }
             outputStream.flush();
             outputStream.close();
-        } catch (IOException e) {
-        	String n = e.getClass().getSimpleName();
-        	if (n.equals("ClientAbortException") || n.equals("EofException")) {
+        } catch (IOException e) {	// ClientAbortException、EofException 直接或间接继承自 IOException
+        	String name = e.getClass().getSimpleName();
+        	if (name.equals("ClientAbortException") || name.equals("EofException")) {
         	} else {
         		throw new RenderException(e);
         	}
@@ -226,9 +226,9 @@ public class FileRender extends Render {
             outputStream.flush();
             outputStream.close();
         }
-        catch (IOException e) {
-        	String n = e.getClass().getSimpleName();
-        	if (n.equals("ClientAbortException") || n.equals("EofException")) {
+        catch (IOException e) {	// ClientAbortException、EofException 直接或间接继承自 IOException
+        	String name = e.getClass().getSimpleName();
+        	if (name.equals("ClientAbortException") || name.equals("EofException")) {
         	} else {
         		throw new RenderException(e);
         	}

+ 8 - 1
src/main/java/com/jfinal/render/QrCodeRender.java

@@ -9,6 +9,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
 import com.jfinal.kit.StrKit;
 import com.jfinal.render.Render;
 import com.jfinal.render.RenderException;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -104,7 +105,13 @@ public class QrCodeRender extends Render {
 
 			// 经测试 200 X 200 大小的二维码使用 "png" 格式只有 412B,而 "jpg" 却达到 15KB
 			MatrixToImageWriter.writeToStream(bitMatrix, "png", response.getOutputStream());    // format: "jpg"、"png"
-		}catch (Exception e) {
+		} catch (IOException e) {	// ClientAbortException、EofException 直接或间接继承自 IOException
+			String name = e.getClass().getSimpleName();
+        	if ("ClientAbortException".equals(name) || "EofException".equals(name)) {
+        	} else {
+        		throw new RenderException(e);
+        	}
+		} catch (Exception e) {
 			throw new RenderException(e);
 		}
 	}

+ 11 - 1
src/main/java/com/jfinal/render/TemplateRender.java

@@ -16,6 +16,7 @@
 
 package com.jfinal.render;
 
+import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -58,7 +59,16 @@ public class TemplateRender extends Render {
         try {
         	OutputStream os = response.getOutputStream();
         	engine.getTemplate(view).render(data, os);
-		} catch (Exception e) {
+        } catch (RuntimeException e) {	// 捕获 ByteWriter.close() 抛出的 RuntimeException
+        	Throwable cause = e.getCause();
+        	if (cause instanceof IOException) {	// ClientAbortException、EofException 直接或间接继承自 IOException
+	        	String name = cause.getClass().getSimpleName();
+	        	if ("ClientAbortException".equals(name) || "EofException".equals(name)) {
+	        		return ;
+	        	}
+	        }
+        	throw e;
+		} catch (IOException e) {
 			throw new RenderException(e);
 		}
 	}