Merge remote branch 'origin/SWT3.7_UrlUpdates' into oss-master

This commit is contained in:
Joel Dice 2011-12-29 11:00:59 -07:00
commit 9ba7c504da
6 changed files with 139 additions and 2 deletions

View File

@ -61,6 +61,10 @@ public class File implements Serializable {
return isFile(path);
}
public boolean isAbsolute() {
return path.equals(toAbsolutePath(path));
}
private static native boolean canRead(String path);
public boolean canRead() {

View File

@ -12,8 +12,10 @@ package java.lang;
public final class Float extends Number {
public static final Class TYPE = Class.forCanonicalName("F");
private final float value;
private static final int EXP_BIT_MASK = 0x7F800000;
private static final int SIGNIF_BIT_MASK = 0x007FFFFF;
private final float value;
public Float(String value) {
this.value = parseFloat(value);
@ -88,6 +90,17 @@ public final class Float extends Number {
throw new NumberFormatException(s);
}
}
public static int floatToIntBits(float value) {
int result = floatToRawIntBits(value);
// Check for NaN based on values of bit fields, maximum
// exponent and nonzero significand.
if (((result & EXP_BIT_MASK) == EXP_BIT_MASK) && (result & SIGNIF_BIT_MASK) != 0) {
result = 0x7fc00000;
}
return result;
}
public static native int floatToRawIntBits(float value);

View File

@ -19,6 +19,8 @@ public final class URL {
private String host;
private int port;
private String file;
private String path;
private String query;
private String ref;
public URL(String s) throws MalformedURLException {
@ -55,6 +57,14 @@ public final class URL {
public String getRef() {
return ref;
}
public String getPath() {
return path;
}
public String getQuery() {
return query;
}
public URLConnection openConnection() throws IOException {
return handler.openConnection(this);
@ -90,5 +100,13 @@ public final class URL {
this.port = port;
this.file = file;
this.ref = ref;
int q = file.lastIndexOf('?');
if (q != -1) {
this.query = file.substring(q + 1);
this.path = file.substring(0, q);
} else {
this.path = file;
}
}
}

29
test/Files.java Normal file
View File

@ -0,0 +1,29 @@
import java.io.File;
public class Files {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static void isAbsoluteTest(boolean absolutePath) {
File file = new File("test.txt");
if (absolutePath) {
file = file.getAbsoluteFile();
}
boolean isAbsolute = file.isAbsolute();
if (absolutePath) {
expect(isAbsolute);
} else {
expect(!isAbsolute);
}
}
public static void main(String[] args) {
isAbsoluteTest(true);
isAbsoluteTest(false);
}
}

View File

@ -229,5 +229,36 @@ public class Floats {
double d = (double) z;
expect(d == 12345.0);
}
// Test floatToIntBits
{
int orig = 0x7f800001;
float NaN = Float.intBitsToFloat(orig);
int result = Float.floatToIntBits(NaN);
int expected = 0x7fc00000;
expect(result == expected);
}
{
int orig = 0x7f801001;
float NaN = Float.intBitsToFloat(orig);
int result = Float.floatToIntBits(NaN);
int expected = 0x7fc00000;
expect(result == expected);
}
{
int orig = 0x00800001;
float number = Float.intBitsToFloat(orig);
int result = Float.floatToIntBits(number);
expect(result == orig);
}
{
int orig = 0x80800003;
float number = Float.intBitsToFloat(orig);
int result = Float.floatToIntBits(number);
expect(result == orig);
}
}
}

42
test/UrlTest.java Normal file
View File

@ -0,0 +1,42 @@
import java.net.MalformedURLException;
import java.net.URL;
public class UrlTest {
private static String query="var1=val1&var2=val2";
private static String path="testpath";
private static String domain="file://www.readytalk.com";
private static String file=path + "?" + query;
private static URL url;
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static void setupURL() throws MalformedURLException {
StringBuilder builder = new StringBuilder();
builder.append(domain);
builder.append("/");
builder.append(file);
url = new URL(builder.toString());
}
private static void testGetPath() {
expect(url.getPath().equals(path));
}
private static void testGetFile() {
expect(url.getFile().equals(file));
}
private static void testGetQuery() {
expect(url.getQuery().equals(query));
}
public static void main(String[] args) throws MalformedURLException {
setupURL();
testGetPath();
testGetFile();
testGetQuery();
}
}