summaryrefslogtreecommitdiffstats
path: root/support/src
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-11-29 16:01:57 -0800
committerJesse Wilson <jessewilson@google.com>2010-11-29 16:03:53 -0800
commit086fd0244a54fa5ecf13ea66d49b22b36d7d456e (patch)
tree243689dc9a328f2113075f004383a858a38844fa /support/src
parent1a3dfbe49a3dcd7c855972dadccb9226468359d5 (diff)
downloadlibcore-086fd0244a54fa5ecf13ea66d49b22b36d7d456e.zip
libcore-086fd0244a54fa5ecf13ea66d49b22b36d7d456e.tar.gz
libcore-086fd0244a54fa5ecf13ea66d49b22b36d7d456e.tar.bz2
Fix XML DOM test failures and close guard warnings.
Fix KxmlParser to capture the DTD's root element name, system ID and public ID. This is more robust than capturing the same in the pull-to-DOM adapter. Fix close guard warnings in XML tests. Close input streams of resource files. Don't catch exceptions only to call fail(). http://b/3090550 Change-Id: I7cfafde58cc28af79c48386a4d124803c8791328
Diffstat (limited to 'support/src')
-rw-r--r--support/src/test/java/tests/support/resource/Support_Resources.java63
1 files changed, 5 insertions, 58 deletions
diff --git a/support/src/test/java/tests/support/resource/Support_Resources.java b/support/src/test/java/tests/support/resource/Support_Resources.java
index 9643347..3927883 100644
--- a/support/src/test/java/tests/support/resource/Support_Resources.java
+++ b/support/src/test/java/tests/support/resource/Support_Resources.java
@@ -17,6 +17,7 @@
package tests.support.resource;
+import libcore.base.Streams;
import tests.support.Support_Configuration;
import java.io.File;
@@ -24,9 +25,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
public class Support_Resources {
@@ -116,23 +115,17 @@ public class Support_Resources {
return File.createTempFile("hyts_", suffix, null);
}
- public static void copyLocalFileto(File dest, InputStream in)
- throws FileNotFoundException, IOException {
+ public static void copyLocalFileto(File dest, InputStream in) throws IOException {
if (!dest.exists()) {
FileOutputStream out = new FileOutputStream(dest);
- int result;
- byte[] buf = new byte[4096];
- while ((result = in.read(buf)) != -1) {
- out.write(buf, 0, result);
- }
- in.close();
+ Streams.copy(in, out);
out.close();
dest.deleteOnExit();
}
+ in.close();
}
- public static File getExternalLocalFile(String url) throws IOException,
- MalformedURLException {
+ public static File getExternalLocalFile(String url) throws IOException {
File resources = createTempFolder();
InputStream in = new URL(url).openStream();
File temp = new File(resources.toString() + "/local.tmp");
@@ -151,7 +144,6 @@ public class Support_Resources {
* @return - resource input stream
*/
public static InputStream getResourceStream(String name) {
-
InputStream is = Support_Resources.class.getResourceAsStream(name);
if (is == null) {
@@ -165,51 +157,6 @@ public class Support_Resources {
return is;
}
- /**
- * Util method to write resource files directly to an OutputStream.
- *
- * @param name - name of resource file.
- * @param out - OutputStream to write to.
- * @return - number of bytes written to out.
- */
- public static int writeResourceToStream(String name, OutputStream out) {
- InputStream input = getResourceStream(name);
- byte[] buffer = new byte[512];
- int total = 0;
- int count;
- try {
- count = input.read(buffer);
- while (count != -1) {
- out.write(buffer, 0, count);
- total = total + count;
- count = input.read(buffer);
- }
- return total;
- } catch (IOException e) {
- throw new RuntimeException("Failed to write to passed stream.", e);
- }
- }
-
- /**
- * Util method to get absolute path to resource file
- *
- * @param name - name of resource file
- * @return - path to resource
- */
- public static String getAbsoluteResourcePath(String name) {
-
- URL url = ClassLoader.getSystemClassLoader().getResource(name);
- if (url == null) {
- throw new RuntimeException("Failed to load resource: " + name);
- }
-
- try {
- return new File(url.toURI()).getAbsolutePath();
- } catch (URISyntaxException e) {
- throw new RuntimeException("Failed to load resource: " + name);
- }
- }
-
public static File resourceToTempFile(String path) throws IOException {
File f = File.createTempFile("out", ".xml");
f.deleteOnExit();