diff options
Diffstat (limited to 'libjava/classpath/vm/reference/java')
4 files changed, 131 insertions, 138 deletions
diff --git a/libjava/classpath/vm/reference/java/io/VMFile.java b/libjava/classpath/vm/reference/java/io/VMFile.java index 13d256d..4f708a4 100644 --- a/libjava/classpath/vm/reference/java/io/VMFile.java +++ b/libjava/classpath/vm/reference/java/io/VMFile.java @@ -116,6 +116,27 @@ final class VMFile */ static native boolean mkdir(String dirpath); + /** + * Set the read permission of the file. + */ + public static synchronized native boolean setReadable(String path, + boolean readable, + boolean ownerOnly); + + /** + * Set the write permission of the file. + */ + public static synchronized native boolean setWritable(String path, + boolean writable, + boolean ownerOnly); + + /** + * Set the execute permission of the file. + */ + public static synchronized native boolean setExecutable(String path, + boolean executable, + boolean ownerOnly); + /* * This native method does the actual check of whether or not a file * is a plain file or not. It also handles the existence check to @@ -127,7 +148,7 @@ final class VMFile * This native method checks file permissions for writing */ static synchronized native boolean canWrite(String path); - + /** * This methods checks if a directory can be written to. */ @@ -150,6 +171,11 @@ final class VMFile */ static synchronized native boolean canRead(String path); + /** + * This native method checks file permissions for execution + */ + static synchronized native boolean canExecute(String path); + /* * This method does the actual check of whether or not a file is a * directory or not. It also handle the existence check to eliminate diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Method.java b/libjava/classpath/vm/reference/java/lang/reflect/Method.java index c520f05..2db59fe 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Method.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Method.java @@ -1,5 +1,5 @@ /* java.lang.reflect.Method - reflection of Java methods - Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2002, 2005, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -449,4 +449,17 @@ extends AccessibleObject implements Member, GenericDeclaration MethodSignatureParser p = new MethodSignatureParser(this, sig); return p.getGenericReturnType(); } + + /** + * If this method is an annotation method, returns the default + * value for the method. If there is no default value, or if the + * method is not a member of an annotation type, returns null. + * Primitive types are wrapped. + * + * @throws TypeNotPresentException if the method returns a Class, + * and the class cannot be found + * + * @since 1.5 + */ + public native Object getDefaultValue(); } diff --git a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java index 7f1e3ad..e28e616 100644 --- a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java +++ b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java @@ -43,7 +43,6 @@ import gnu.classpath.Configuration; import java.nio.ByteBuffer; import java.util.HashSet; import java.util.Set; -import java.util.Vector; /** * This class models a network interface on the host computer. A network @@ -58,12 +57,12 @@ import java.util.Vector; final class VMNetworkInterface { String name; - Set addresses; + Set<InetAddress> addresses; VMNetworkInterface(String name) { this.name = name; - addresses = new HashSet(); + addresses = new HashSet<InetAddress>(); } /** @@ -72,7 +71,7 @@ final class VMNetworkInterface */ public VMNetworkInterface() { - addresses = new HashSet(); + addresses = new HashSet<InetAddress>(); try { addresses.add(InetAddress.getByName("0.0.0.0")); diff --git a/libjava/classpath/vm/reference/java/util/VMTimeZone.java b/libjava/classpath/vm/reference/java/util/VMTimeZone.java index 86b6258..992ecaf 100644 --- a/libjava/classpath/vm/reference/java/util/VMTimeZone.java +++ b/libjava/classpath/vm/reference/java/util/VMTimeZone.java @@ -1,5 +1,5 @@ /* java.util.VMTimeZone - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,6 +40,9 @@ exception statement from your version. */ package java.util; import gnu.classpath.Configuration; +import gnu.classpath.SystemProperties; +import gnu.java.util.ZoneInfo; +import java.util.TimeZone; import java.io.*; @@ -75,9 +78,10 @@ final class VMTimeZone * The reference implementation which is made for GNU/Posix like * systems calls <code>System.getenv("TZ")</code>, * <code>readTimeZoneFile("/etc/timezone")</code>, - * <code>readtzFile("/etc/localtime")</code> and finally - * <code>getSystemTimeZoneId()</code> till a supported TimeZone is - * found through <code>TimeZone.getDefaultTimeZone(String)</code>. + * <code>ZoneInfo.readTZFile((String)null, "/etc/localtime")</code> + * and finally <code>getSystemTimeZoneId()</code> till a supported + * TimeZone is found through + * <code>TimeZone.getDefaultTimeZone(String)</code>. * If every method fails <code>null</code> is returned (which means * the TimeZone code will fall back on GMT as default time zone). * <p> @@ -108,9 +112,51 @@ final class VMTimeZone // Try to parse /etc/localtime if (zone == null) { - tzid = readtzFile("/etc/localtime"); - if (tzid != null && !tzid.equals("")) - zone = TimeZone.getDefaultTimeZone(tzid); + zone = ZoneInfo.readTZFile((String) null, "/etc/localtime"); + if (zone != null) + { + // Try to find a more suitable ID for the /etc/localtime + // timezone. + // Sometimes /etc/localtime is a symlink to some + // /usr/share/zoneinfo/ file. + String id = null; + try + { + id = new File("/etc/localtime").getCanonicalPath(); + if (id != null) + { + String zoneinfo_dir + = SystemProperties.getProperty("gnu.java.util.zoneinfo.dir"); + if (zoneinfo_dir != null) + zoneinfo_dir + = new File(zoneinfo_dir + + File.separatorChar).getCanonicalPath(); + if (zoneinfo_dir != null && id.startsWith(zoneinfo_dir)) + { + int pos = zoneinfo_dir.length(); + while (pos < id.length() + && id.charAt(pos) == File.separatorChar) + pos++; + if (pos < id.length()) + id = id.substring(pos); + else + id = null; + } + else + id = null; + } + } + catch (IOException ioe) + { + id = null; + } + + if (id == null) + id = readSysconfigClockFile("/etc/sysconfig/clock"); + + if (id != null) + zone.setID(id); + } } // Try some system specific way @@ -186,121 +232,46 @@ final class VMTimeZone } /** - * Tries to read a file as a "standard" tzfile and return a time - * zone id string as expected by <code>getDefaultTimeZone(String)</code>. - * If the file doesn't exist, an IOException occurs or it isn't a tzfile - * that can be parsed null is returned. - * <p> - * The tzfile structure (as also used by glibc) is described in the Olson - * tz database archive as can be found at - * <code>ftp://elsie.nci.nih.gov/pub/</code>. + * Tries to read the time zone name from a file. + * If the file cannot be read or an IOException occurs null is returned. * <p> - * At least the following platforms support the tzdata file format - * and /etc/localtime (GNU/Linux, Darwin, Solaris and FreeBSD at - * least). Some systems (like Darwin) don't start the file with the - * required magic bytes 'TZif', this implementation can handle - * that). + * The /etc/sysconfig/clock file is not standard, but a lot of systems + * have it. The file is included by shell scripts and the timezone + * name is defined in ZONE variable. + * This routine should grok it with or without quotes: + * ZONE=America/New_York + * or + * ZONE="Europe/London" */ - private static String readtzFile(String file) + private static String readSysconfigClockFile(String file) { - File f = new File(file); - if (!f.exists()) - return null; - - DataInputStream dis = null; + BufferedReader br = null; try { - FileInputStream fis = new FileInputStream(f); - BufferedInputStream bis = new BufferedInputStream(fis); - dis = new DataInputStream(bis); - - // Make sure we are reading a tzfile. - byte[] tzif = new byte[4]; - dis.readFully(tzif); - if (tzif[0] == 'T' && tzif[1] == 'Z' - && tzif[2] == 'i' && tzif[3] == 'f') - // Reserved bytes, ttisgmtcnt, ttisstdcnt and leapcnt - skipFully(dis, 16 + 3 * 4); - else - // Darwin has tzdata files that don't start with the TZif marker - skipFully(dis, 16 + 3 * 4 - 4); - - int timecnt = dis.readInt(); - int typecnt = dis.readInt(); - if (typecnt > 0) + FileInputStream fis = new FileInputStream(file); + BufferedInputStream bis = new BufferedInputStream(fis); + br = new BufferedReader(new InputStreamReader(bis)); + + for (String line = br.readLine(); line != null; line = br.readLine()) { - int charcnt = dis.readInt(); - // Transition times plus indexed transition times. - skipFully(dis, timecnt * (4 + 1)); - - // Get last gmt_offset and dst/non-dst time zone names. - int abbrind = -1; - int dst_abbrind = -1; - int gmt_offset = 0; - while (typecnt-- > 0) - { - // gmtoff - int offset = dis.readInt(); - int dst = dis.readByte(); - if (dst == 0) - { - abbrind = dis.readByte(); - gmt_offset = offset; - } - else - dst_abbrind = dis.readByte(); - } - - // gmt_offset is the offset you must add to UTC/GMT to - // get the local time, we need the offset to add to - // the local time to get UTC/GMT. - gmt_offset *= -1; - - // Turn into hours if possible. - if (gmt_offset % 3600 == 0) - gmt_offset /= 3600; - - if (abbrind >= 0) + line = line.trim(); + if (line.length() < 8 || !line.startsWith("ZONE=")) + continue; + int posstart = 6; + int posend; + if (line.charAt(5) == '"') + posend = line.indexOf('"', 6); + else if (line.charAt(5) == '\'') + posend = line.indexOf('\'', 6); + else { - byte[] names = new byte[charcnt]; - dis.readFully(names); - int j = abbrind; - while (j < charcnt && names[j] != 0) - j++; - - String zonename = new String(names, abbrind, j - abbrind, - "ASCII"); - - String dst_zonename; - if (dst_abbrind >= 0) - { - j = dst_abbrind; - while (j < charcnt && names[j] != 0) - j++; - dst_zonename = new String(names, dst_abbrind, - j - dst_abbrind, "ASCII"); - } - else - dst_zonename = ""; - - // Only use gmt offset when necessary. - // Also special case GMT+/- timezones. - String offset_string; - if ("".equals(dst_zonename) - && (gmt_offset == 0 - || zonename.startsWith("GMT+") - || zonename.startsWith("GMT-"))) - offset_string = ""; - else - offset_string = Integer.toString(gmt_offset); - - String id = zonename + offset_string + dst_zonename; - - return id; + posstart = 5; + posend = line.length(); } + if (posend < 0) + return null; + return line.substring(posstart, posend); } - - // Something didn't match while reading the file. return null; } catch (IOException ioe) @@ -312,31 +283,15 @@ final class VMTimeZone { try { - if (dis != null) - dis.close(); + if (br != null) + br.close(); } - catch(IOException ioe) + catch (IOException ioe) { // Error while close, nothing we can do. } } } - - /** - * Skips the requested number of bytes in the given InputStream. - * Throws EOFException if not enough bytes could be skipped. - * Negative numbers of bytes to skip are ignored. - */ - private static void skipFully(InputStream is, long l) throws IOException - { - while (l > 0) - { - long k = is.skip(l); - if (k <= 0) - throw new EOFException(); - l -= k; - } - } /** * Tries to get the system time zone id through native code. |