- Changed char_to_java() to use C charset instead of JVM's default encoding.

- Changed PosixFileFunctions.readLink() to return String instead of byte[].
This commit is contained in:
Adam Murdoch
2012-09-09 10:22:40 +10:00
parent af53881b0b
commit 7e2a573ff2
6 changed files with 25 additions and 23 deletions

View File

@@ -36,11 +36,11 @@ public class DefaultPosixFile implements PosixFile {
@Override
public String readLink(File link) throws NativeException {
FunctionResult result = new FunctionResult();
byte[] encodedContents = PosixFileFunctions.readlink(encode(link), result);
String contents = PosixFileFunctions.readlink(encode(link), result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not read symlink %s: %s", link, result.getMessage()));
}
return decode(encodedContents);
return contents;
}
@Override
@@ -52,14 +52,6 @@ public class DefaultPosixFile implements PosixFile {
}
}
private String decode(byte[] path) {
try {
return new String(path, 0, path.length, characterEncoding);
} catch (UnsupportedEncodingException e) {
throw new NativeException(String.format("Could not decode path using encoding %s.", characterEncoding), e);
}
}
private byte[] encode(File file) {
return encode(file.getPath());
}

View File

@@ -4,7 +4,7 @@ import net.rubygrapefruit.platform.internal.FunctionResult;
import net.rubygrapefruit.platform.internal.MutableSystemInfo;
public class NativeLibraryFunctions {
public static final int VERSION = 7;
public static final int VERSION = 8;
public static native int getVersion();

View File

@@ -10,5 +10,5 @@ public class PosixFileFunctions {
public static native void symlink(byte[] file, byte[] content, FunctionResult result);
public static native byte[] readlink(byte[] file, FunctionResult result);
public static native String readlink(byte[] file, FunctionResult result);
}