Patch to close InputStreams contributed by Jürg Lehni.
This commit is contained in:
parent
f90f174719
commit
426a0d0c9d
2 changed files with 66 additions and 65 deletions
|
@ -127,7 +127,9 @@ public class ImageObject {
|
||||||
Object arg = args[0];
|
Object arg = args[0];
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
ImageInfo info = new ImageInfo();
|
ImageInfo info = new ImageInfo();
|
||||||
|
Object ret = null;
|
||||||
|
|
||||||
|
try {
|
||||||
if (arg instanceof Wrapper) {
|
if (arg instanceof Wrapper) {
|
||||||
arg = ((Wrapper) arg).unwrap();
|
arg = ((Wrapper) arg).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -137,42 +139,24 @@ public class ImageObject {
|
||||||
} else if (arg instanceof byte[]) {
|
} else if (arg instanceof byte[]) {
|
||||||
in = new ByteArrayInputStream((byte[]) arg);
|
in = new ByteArrayInputStream((byte[]) arg);
|
||||||
} else if (arg instanceof File) {
|
} else if (arg instanceof File) {
|
||||||
try {
|
|
||||||
in = new FileInputStream((File) arg);
|
in = new FileInputStream((File) arg);
|
||||||
} catch (FileNotFoundException fnf) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if (arg instanceof File) {
|
} else if (arg instanceof File) {
|
||||||
try {
|
|
||||||
in = new FileInputStream((File) arg);
|
in = new FileInputStream((File) arg);
|
||||||
} catch (FileNotFoundException fnf) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if (arg instanceof FileObject) {
|
} else if (arg instanceof FileObject) {
|
||||||
try {
|
|
||||||
in = new FileInputStream(((FileObject)arg).getFile());
|
in = new FileInputStream(((FileObject)arg).getFile());
|
||||||
} catch (FileNotFoundException fnf) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if (arg instanceof String) {
|
} else if (arg instanceof String) {
|
||||||
String str = (String) arg;
|
String str = (String) arg;
|
||||||
// try to interpret argument as URL if it contains a colon,
|
// try to interpret argument as URL if it contains a colon,
|
||||||
// otherwise or if URL is malformed interpret as file name.
|
// otherwise or if URL is malformed interpret as file name.
|
||||||
try {
|
|
||||||
if (str.indexOf(":") > -1) {
|
if (str.indexOf(":") > -1) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(str);
|
URL url = new URL(str);
|
||||||
in = url.openStream();
|
in = url.openStream();
|
||||||
} catch (MalformedURLException mux) {
|
} catch (MalformedURLException mux) {
|
||||||
in = new FileInputStream(str);
|
in = new FileInputStream(str);
|
||||||
} catch (IOException iox) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
in = new FileInputStream((String) arg);
|
in = new FileInputStream(str);
|
||||||
}
|
|
||||||
} catch (FileNotFoundException fnf) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,10 +168,20 @@ public class ImageObject {
|
||||||
|
|
||||||
info.setInput(in);
|
info.setInput(in);
|
||||||
if (info.check()) {
|
if (info.check()) {
|
||||||
return Context.toObject(info, scope);
|
ret = Context.toObject(info, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
} catch (IOException e) {
|
||||||
|
// do nothing, returns null later
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException ee) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,7 +448,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
InputStream in = cx.getResourceAsStream(forward);
|
InputStream in = cx.getResourceAsStream(forward);
|
||||||
if (in == null)
|
if (in == null)
|
||||||
throw new IOException("Can't read "+path);
|
throw new IOException("Can't read "+path);
|
||||||
|
try {
|
||||||
OutputStream out = res.getOutputStream();
|
OutputStream out = res.getOutputStream();
|
||||||
|
|
||||||
int bufferSize = 4096;
|
int bufferSize = 4096;
|
||||||
|
@ -467,6 +467,9 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
length -= l;
|
length -= l;
|
||||||
out.write(buffer, 0, l);
|
out.write(buffer, 0, l);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUpload getUpload(HttpServletRequest request, String encoding) throws Exception {
|
FileUpload getUpload(HttpServletRequest request, String encoding) throws Exception {
|
||||||
|
@ -738,6 +741,10 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// append trailing "/" if it is contained in original URI
|
// append trailing "/" if it is contained in original URI
|
||||||
|
|
||||||
|
// append trailing "/" if it is contained in original URI
|
||||||
|
if (uri.endsWith("/"))
|
||||||
|
pathbuffer.append('/');
|
||||||
if (uri.endsWith("/"))
|
if (uri.endsWith("/"))
|
||||||
pathbuffer.append('/');
|
pathbuffer.append('/');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue