Skip to content
Permalink
Browse files

Fix a few bugs in the file I/O abstraction layer

  • Loading branch information
ndw committed Feb 12, 2014
1 parent 889b0e1 commit db6669ecd2f82e1ebd392ee01924bd856d9f5443
@@ -20,6 +20,8 @@

package com.xmlcalabash.io;

import com.xmlcalabash.core.XProcException;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileFilter;
@@ -148,6 +150,11 @@ public void listEachEntry(String href, String base, String accept,
URI uri = baseURI.resolve(href);
if ("file".equalsIgnoreCase(uri.getScheme())) {
File file = new File(uri);

if (!file.canRead()) {
throw XProcException.stepError(12);
}

if (file.isDirectory()) {
for (File f : listAcceptableFiles(file, accept)) {
String type;
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -78,7 +79,17 @@ public void readEntry(String href, String base, String accept,
try {
String type = connection.getContentType();
URI id = URI.create(connection.getURL().toExternalForm());
long len = connection.getContentLengthLong();
long len = 0;

// Call getContentLengthLong if it's available
try {
Method lenMethod = connection.getClass().getDeclaredMethod("getContentLengthLong");
lenMethod.invoke(connection);
} catch (Exception e) {
// Whatever...
len = connection.getContentLength();
}

handler.load(id, type, stream, len);
} finally {
stream.close();
@@ -157,7 +157,11 @@ public void list(URI id, String media, long lastModified) throws IOException {
}

String getName(URI id) {
return id.getPath().replaceAll("^.*/", "");
String path = id.getPath();
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path.replaceAll("^.*/", "");
}

boolean isFile(URI id) throws IOException {

0 comments on commit db6669e

Please sign in to comment.
You can’t perform that action at this time.