You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/08/18 04:27:35 UTC
svn commit: r432466 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io:
CharArrayReader.java CharArrayWriter.java DataInputStream.java File.java
Author: ndbeyer
Date: Thu Aug 17 19:27:32 2006
New Revision: 432466
URL: http://svn.apache.org/viewvc?rev=432466&view=rev
Log:
Code cleanup; remove compiler warnings, etc
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java?rev=432466&r1=432465&r2=432466&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java Thu Aug 17 19:27:32 2006
@@ -15,6 +15,7 @@
package java.io;
+import org.apache.harmony.luni.util.Msg;
/**
* CharArrayReader is used as a buffered character input stream on a character
@@ -30,7 +31,7 @@
/**
* Current buffer position.
*/
- protected int pos = 0;
+ protected int pos;
/**
* Current mark position.
@@ -40,7 +41,7 @@
/**
* The ending index of the buffer.
*/
- protected int count = 0;
+ protected int count;
/**
* Construct a CharArrayReader on the char array <code>buffer</code>. The
@@ -78,8 +79,9 @@
/* This is according to spec */
this.count = this.pos + length < buf.length ? length : buf.length;
- } else
- throw new IllegalArgumentException();
+ } else {
+ throw new IllegalArgumentException();
+ }
}
/**
@@ -88,10 +90,12 @@
* effect.
*
*/
- public void close() {
+ @Override
+ public void close() {
synchronized (lock) {
- if (isOpen())
- buf = null;
+ if (isOpen()) {
+ buf = null;
+ }
}
}
@@ -116,12 +120,14 @@
* @throws IOException
* If an error occurs attempting to mark this CharArrayReader.
*/
- public void mark(int readLimit) throws IOException {
+ @Override
+ public void mark(int readLimit) throws IOException {
synchronized (lock) {
- if (isOpen())
- markedPos = pos;
- else
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ if (isOpen()) {
+ markedPos = pos;
+ } else {
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+ }
}
}
@@ -131,7 +137,8 @@
*
* @return indicates whether or not mark() and reset() are supported.
*/
- public boolean markSupported() {
+ @Override
+ public boolean markSupported() {
return true;
}
@@ -145,14 +152,16 @@
* @throws IOException
* If the CharArrayReader is already closed.
*/
- public int read() throws IOException {
+ @Override
+ public int read() throws IOException {
synchronized (lock) {
if (isOpen()) {
- if (pos != count)
- return buf[pos++];
+ if (pos != count) {
+ return buf[pos++];
+ }
return -1;
}
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
}
@@ -175,7 +184,8 @@
* If the CharArrayReader is closed.
*/
- public int read(char buffer[], int offset, int len) throws IOException {
+ @Override
+ public int read(char buffer[], int offset, int len) throws IOException {
// avoid int overflow
if (0 <= offset && offset <= buffer.length && 0 <= len
&& len <= buffer.length - offset) {
@@ -191,7 +201,7 @@
}
return -1;
}
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
}
throw new ArrayIndexOutOfBoundsException();
@@ -212,12 +222,13 @@
* @throws IOException
* If the CharArrayReader is closed.
*/
- public boolean ready() throws IOException {
+ @Override
+ public boolean ready() throws IOException {
synchronized (lock) {
if (isOpen()) {
return pos != count;
}
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
}
@@ -230,12 +241,14 @@
* @throws IOException
* If this CharArrayReader has already been closed.
*/
- public void reset() throws IOException {
+ @Override
+ public void reset() throws IOException {
synchronized (lock) {
- if (isOpen())
- pos = markedPos != -1 ? markedPos : 0;
- else
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ if (isOpen()) {
+ pos = markedPos != -1 ? markedPos : 0;
+ } else {
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
+ }
}
}
@@ -251,11 +264,13 @@
* @throws IOException
* If this CharArrayReader has already been closed.
*/
- public long skip(long n) throws IOException {
+ @Override
+ public long skip(long n) throws IOException {
synchronized (lock) {
if (isOpen()) {
- if (n <= 0)
- return 0;
+ if (n <= 0) {
+ return 0;
+ }
long skipped = 0;
if (n < this.count - pos) {
pos = pos + (int) n;
@@ -266,7 +281,7 @@
}
return skipped;
}
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K0060")); //$NON-NLS-1$
+ throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java?rev=432466&r1=432465&r2=432466&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayWriter.java Thu Aug 17 19:27:32 2006
@@ -15,11 +15,13 @@
package java.io;
+import org.apache.harmony.luni.util.Msg;
+
/**
* CharArrayWriter is used as a character output stream on a character array.
* The buffer used to store the written characters will grow as needed to
- * accomodate more characters as they are written.
+ * accommodate more characters as they are written.
*
*/
public class CharArrayWriter extends Writer {
@@ -59,9 +61,9 @@
if (initialSize >= 0) {
buf = new char[initialSize];
lock = buf;
- } else
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg
- .getString("K005e")); //$NON-NLS-1$
+ } else {
+ throw new IllegalArgumentException(Msg.getString("K005e")); //$NON-NLS-1$
+ }
}
/**
@@ -69,14 +71,16 @@
* particular implementation does nothing.
*
*/
- public void close() {
+ @Override
+ public void close() {
/* empty */
}
private void expand(int i) {
/* Can the buffer handle @i more chars, if not expand it */
- if (count + i <= buf.length)
- return;
+ if (count + i <= buf.length) {
+ return;
+ }
char[] newbuf = new char[buf.length + (2 * i)];
System.arraycopy(buf, 0, newbuf, 0, count);
@@ -89,7 +93,8 @@
*
*/
- public void flush() {
+ @Override
+ public void flush() {
/* empty */
}
@@ -139,7 +144,8 @@
*
* @return String this CharArrayWriters contents as a new String.
*/
- public String toString() {
+ @Override
+ public String toString() {
synchronized (lock) {
return new String(buf, 0, count);
}
@@ -156,7 +162,8 @@
* @param len
* maximum number of characters to write
*/
- public void write(char[] c, int offset, int len) {
+ @Override
+ public void write(char[] c, int offset, int len) {
// avoid int overflow
if (0 <= offset && offset <= c.length && 0 <= len
&& len <= c.length - offset) {
@@ -165,8 +172,9 @@
System.arraycopy(c, offset, this.buf, this.count, len);
this.count += len;
}
- } else
- throw new IndexOutOfBoundsException();
+ } else {
+ throw new IndexOutOfBoundsException();
+ }
}
/**
@@ -177,7 +185,8 @@
* @param oneChar
* The character to write
*/
- public void write(int oneChar) {
+ @Override
+ public void write(int oneChar) {
synchronized (lock) {
expand(1);
buf[count++] = (char) oneChar;
@@ -196,10 +205,10 @@
* @param len
* the number of characters to retrieve and write.
*/
- public void write(String str, int offset, int len) {
+ @Override
+ public void write(String str, int offset, int len) {
if (str == null) {
- throw new NullPointerException(org.apache.harmony.luni.util.Msg
- .getString("K0047")); //$NON-NLS-1$
+ throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
if (0 <= offset && offset <= str.length() && 0 <= len
@@ -209,8 +218,9 @@
str.getChars(offset, offset + len, buf, this.count);
this.count += len;
}
- } else
- throw new StringIndexOutOfBoundsException();
+ } else {
+ throw new StringIndexOutOfBoundsException();
+ }
}
/**
@@ -240,7 +250,8 @@
* The character appended to the CharArrayWriter.
* @return The CharArrayWriter.
*/
- public CharArrayWriter append(char c) {
+ @Override
+ public CharArrayWriter append(char c) {
write(c);
return this;
}
@@ -257,7 +268,8 @@
* The CharSequence appended to the CharArrayWriter.
* @return The CharArrayWriter
*/
- public CharArrayWriter append(CharSequence csq) {
+ @Override
+ public CharArrayWriter append(CharSequence csq) {
if (null == csq) {
append(TOKEN_NULL, 0, TOKEN_NULL.length());
} else {
@@ -289,7 +301,8 @@
* If start is less than end, end is greater than the length of
* the CharSequence, or start or end is negative.
*/
- public CharArrayWriter append(CharSequence csq, int start, int end) {
+ @Override
+ public CharArrayWriter append(CharSequence csq, int start, int end) {
if (null == csq) {
csq = TOKEN_NULL;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java?rev=432466&r1=432465&r2=432466&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java Thu Aug 17 19:27:32 2006
@@ -15,6 +15,8 @@
package java.io;
+import org.apache.harmony.luni.util.Msg;
+import org.apache.harmony.luni.util.Util;
/**
* DataInputStream is a filter class which can read typed data from a Stream.
@@ -55,7 +57,8 @@
* @see DataOutput#write(byte[])
* @see DataOutput#write(byte[], int, int)
*/
- public final int read(byte[] buffer) throws IOException {
+ @Override
+ public final int read(byte[] buffer) throws IOException {
return in.read(buffer, 0, buffer.length);
}
@@ -79,7 +82,8 @@
* @see DataOutput#write(byte[])
* @see DataOutput#write(byte[], int, int)
*/
- public final int read(byte[] buffer, int offset, int length)
+ @Override
+ public final int read(byte[] buffer, int offset, int length)
throws IOException {
return in.read(buffer, offset, length);
}
@@ -96,8 +100,9 @@
*/
public final boolean readBoolean() throws IOException {
int temp = in.read();
- if (temp >= 0)
- return temp != 0;
+ if (temp >= 0) {
+ return temp != 0;
+ }
throw new EOFException();
}
@@ -113,8 +118,9 @@
*/
public final byte readByte() throws IOException {
int temp = in.read();
- if (temp >= 0)
- return (byte) temp;
+ if (temp >= 0) {
+ return (byte) temp;
+ }
throw new EOFException();
}
@@ -131,8 +137,9 @@
public final char readChar() throws IOException {
int b1 = in.read();
int b2 = in.read();
- if ((b1 | b2) >= 0)
- return (char) ((b1 << 8) + b2);
+ if ((b1 | b2) >= 0) {
+ return (char) ((b1 << 8) + b2);
+ }
throw new EOFException();
}
@@ -198,14 +205,16 @@
if (result >= 0) {
offset += result;
length -= result;
- } else
- throw new EOFException();
+ } else {
+ throw new EOFException();
+ }
}
- } else
- throw new IndexOutOfBoundsException();
- } else
- throw new NullPointerException(org.apache.harmony.luni.util.Msg
- .getString("K0047")); //$NON-NLS-1$
+ } else {
+ throw new IndexOutOfBoundsException();
+ }
+ } else {
+ throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+ }
}
/**
@@ -223,8 +232,9 @@
int b2 = in.read();
int b3 = in.read();
int b4 = in.read();
- if ((b1 | b2 | b3 | b4) >= 0)
- return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
+ if ((b1 | b2 | b3 | b4) >= 0) {
+ return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
+ }
throw new EOFException();
}
@@ -244,15 +254,17 @@
*
* @deprecated Use BufferedReader
*/
- public final String readLine() throws IOException {
+ @Deprecated
+ public final String readLine() throws IOException {
StringBuffer line = new StringBuffer(80); // Typical line length
boolean foundTerminator = false;
while (true) {
int nextByte = in.read();
switch (nextByte) {
case -1:
- if (line.length() == 0 && !foundTerminator)
- return null;
+ if (line.length() == 0 && !foundTerminator) {
+ return null;
+ }
return line.toString();
case (byte) '\r':
if (foundTerminator) {
@@ -261,8 +273,9 @@
}
foundTerminator = true;
/* Have to be able to peek ahead one byte */
- if (!(in.getClass() == PushbackInputStream.class))
- in = new PushbackInputStream(in);
+ if (!(in.getClass() == PushbackInputStream.class)) {
+ in = new PushbackInputStream(in);
+ }
break;
case (byte) '\n':
return line.toString();
@@ -292,9 +305,10 @@
int b2 = in.read();
int b3 = in.read();
int b4 = in.read();
- if ((b1 | b2 | b3 | b4) >= 0)
- return (((long) i1) << 32) + ((long) b1 << 24) + (b2 << 16)
+ if ((b1 | b2 | b3 | b4) >= 0) {
+ return (((long) i1) << 32) + ((long) b1 << 24) + (b2 << 16)
+ (b3 << 8) + b4;
+ }
throw new EOFException();
}
@@ -311,8 +325,9 @@
public final short readShort() throws IOException {
int b1 = in.read();
int b2 = in.read();
- if ((b1 | b2) >= 0)
- return (short) ((b1 << 8) + b2);
+ if ((b1 | b2) >= 0) {
+ return (short) ((b1 << 8) + b2);
+ }
throw new EOFException();
}
@@ -329,8 +344,9 @@
*/
public final int readUnsignedByte() throws IOException {
int temp = in.read();
- if (temp >= 0)
- return temp;
+ if (temp >= 0) {
+ return temp;
+ }
throw new EOFException();
}
@@ -349,8 +365,9 @@
public final int readUnsignedShort() throws IOException {
int b1 = in.read();
int b2 = in.read();
- if ((b1 | b2) >= 0)
- return ((b1 << 8) + b2);
+ if ((b1 | b2) >= 0) {
+ return ((b1 << 8) + b2);
+ }
throw new EOFException();
}
@@ -408,8 +425,9 @@
* explicitly check and fix their length after sampling.
*/
buf = byteBuf;
- if (buf.length < utfSize)
- buf = byteBuf = new byte[utfSize];
+ if (buf.length < utfSize) {
+ buf = byteBuf = new byte[utfSize];
+ }
out = charBuf;
if (out.length < utfSize) {
out = charBuf = new char[utfSize];
@@ -418,7 +436,7 @@
readFully(buf, 0, utfSize);
String result;
- result = org.apache.harmony.luni.util.Util.convertUTF8WithBuf(buf, out, 0, utfSize);
+ result = Util.convertUTF8WithBuf(buf, out, 0, utfSize);
if (!makeBuf) {
/*
* Do not synchronize useShared on cacheLock, it will make it back
@@ -461,10 +479,12 @@
public final int skipBytes(int count) throws IOException {
int skipped = 0;
long skip;
- while (skipped < count && (skip = in.skip(count - skipped)) != 0)
- skipped += skip;
- if (skipped >= 0)
- return skipped;
+ while (skipped < count && (skip = in.skip(count - skipped)) != 0) {
+ skipped += skip;
+ }
+ if (skipped >= 0) {
+ return skipped;
+ }
throw new EOFException();
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?rev=432466&r1=432465&r2=432466&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java Thu Aug 17 19:27:32 2006
@@ -20,8 +20,13 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.harmony.luni.util.DeleteOnExit;
+import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.luni.util.PriviAction;
+import org.apache.harmony.luni.util.Util;
/**
* File is a class which represents a file name or directory. The file may be
@@ -101,8 +106,9 @@
} else {
this.path = calculatePath(dir.getPath(),name);
}
- } else
- throw new NullPointerException();
+ } else {
+ throw new NullPointerException();
+ }
}
/**
@@ -132,8 +138,9 @@
} else {
this.path = calculatePath(dirPath, name);
}
- } else
- throw new NullPointerException();
+ } else {
+ throw new NullPointerException();
+ }
}
/**
@@ -162,8 +169,9 @@
private String calculatePath(String dirPath, String name) {
// Remove all the proceeding separator chars from name
name = fixSlashes(name);
- while (name.length() > 0 && (name.charAt(0) == separatorChar))
- name = name.substring(1, name.length());
+ while (name.length() > 0 && (name.charAt(0) == separatorChar)) {
+ name = name.substring(1, name.length());
+ }
// Ensure there is a separator char between dirPath and name
dirPath = fixSlashes(dirPath);
@@ -176,37 +184,39 @@
private void checkURI(URI uri) {
if (!uri.isAbsolute()) {
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ throw new IllegalArgumentException(Msg.getString(
"K031a", uri)); //$NON-NLS-1$
} else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { //$NON-NLS-1$
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ throw new IllegalArgumentException(Msg.getString(
"K031b", uri)); //$NON-NLS-1$
}
String temp = uri.getScheme();
if (temp == null || !temp.equals("file")) { //$NON-NLS-1$
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ throw new IllegalArgumentException(Msg.getString(
"K031c", uri)); //$NON-NLS-1$
}
temp = uri.getRawPath();
if (temp == null || temp.length() == 0) {
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ throw new IllegalArgumentException(Msg.getString(
"K031d", uri)); //$NON-NLS-1$
}
if (uri.getRawAuthority() != null) {
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ throw new IllegalArgumentException(Msg.getString(
"K031e", new String[] { "authority", uri.toString() })); //$NON-NLS-1$ //$NON-NLS-2$
}
- if (uri.getRawQuery() != null)
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ if (uri.getRawQuery() != null) {
+ throw new IllegalArgumentException(Msg.getString(
"K031e", new String[] { "query", uri.toString() })); //$NON-NLS-1$//$NON-NLS-2$
+ }
- if (uri.getRawFragment() != null)
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg.getString(
+ if (uri.getRawFragment() != null) {
+ throw new IllegalArgumentException(Msg.getString(
"K031e", new String[] { "fragment", uri.toString() })); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
private static native byte[][] rootsImpl();
@@ -224,11 +234,13 @@
*/
public static File[] listRoots() {
byte[][] rootsList = rootsImpl();
- if (rootsList == null)
- return new File[0];
+ if (rootsList == null) {
+ return new File[0];
+ }
File result[] = new File[rootsList.length];
- for (int i = 0; i < rootsList.length; i++)
- result[i] = new File(org.apache.harmony.luni.util.Util.toString(rootsList[i]));
+ for (int i = 0; i < rootsList.length; i++) {
+ result[i] = new File(Util.toString(rootsList[i]));
+ }
return result;
}
@@ -240,10 +252,11 @@
private String fixSlashes(String origPath) {
int uncIndex = 1;
int length = origPath.length(), newLength = 0;
- if (separatorChar == '/') // disable UNC names
- uncIndex = 0;
- else if (length > 2 && origPath.charAt(1) == ':')
- uncIndex = 2;
+ if (separatorChar == '/') {
+ uncIndex = 0;
+ } else if (length > 2 && origPath.charAt(1) == ':') {
+ uncIndex = 2;
+ }
boolean foundSlash = false;
char newPath[] = origPath.toCharArray();
@@ -294,8 +307,9 @@
*/
public boolean canRead() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return exists() && !isWriteOnlyImpl(properPath(true));
}
@@ -310,8 +324,9 @@
*/
public boolean canWrite() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkWrite(path);
+ if (security != null) {
+ security.checkWrite(path);
+ }
// Cannot use exists() since that does an unwanted read-check.
boolean exists = false;
@@ -372,10 +387,11 @@
*/
public void deleteOnExit() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkDelete(path);
+ if (security != null) {
+ security.checkDelete(path);
+ }
- org.apache.harmony.luni.util.DeleteOnExit.addFile(org.apache.harmony.luni.util.Util
+ DeleteOnExit.addFile(Util
.toString(properPath(true)));
}
@@ -389,9 +405,11 @@
* @return <code>true</code> if the object is the same as this object,
* <code>false</code> otherwise.
*/
- public boolean equals(Object obj) {
- if (!(obj instanceof File))
- return false;
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof File)) {
+ return false;
+ }
if (!caseSensitive) {
return path.equalsIgnoreCase(((File) obj).getPath());
}
@@ -409,11 +427,13 @@
* @see java.lang.SecurityManager#checkRead(FileDescriptor)
*/
public boolean exists() {
- if (path.length() == 0)
- return false;
+ if (path.length() == 0) {
+ return false;
+ }
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return existsImpl(properPath(true));
}
@@ -428,7 +448,7 @@
*/
public String getAbsolutePath() {
byte[] absolute = properPath(false);
- return org.apache.harmony.luni.util.Util.toString(absolute);
+ return Util.toString(absolute);
}
/**
@@ -466,14 +486,16 @@
byte[] pathBytes = result;
do {
byte[] linkBytes = getLinkImpl(pathBytes);
- if (linkBytes == pathBytes)
- break;
+ if (linkBytes == pathBytes) {
+ break;
+ }
if (linkBytes[0] == separatorChar) {
pathBytes = linkBytes;
} else {
int index = pathBytes.length - 1;
- while (pathBytes[index] != separatorChar)
- index--;
+ while (pathBytes[index] != separatorChar) {
+ index--;
+ }
byte[] temp = new byte[index + 1 + linkBytes.length];
System.arraycopy(pathBytes, 0, temp, 0, index + 1);
System.arraycopy(linkBytes, 0, temp, index + 1,
@@ -482,30 +504,36 @@
}
exists = existsImpl(pathBytes);
} while (exists);
- if (exists)
- result = pathBytes;
+ if (exists) {
+ result = pathBytes;
+ }
int numSeparators = 1;
- for (int i = 0; i < result.length; i++)
- if (result[i] == separatorChar)
- numSeparators++;
+ for (int i = 0; i < result.length; i++) {
+ if (result[i] == separatorChar) {
+ numSeparators++;
+ }
+ }
int sepLocations[] = new int[numSeparators];
int rootLoc = 0;
- if (separatorChar != '/')
- if (result[0] == '\\')
- rootLoc = (result.length > 1 && result[1] == '\\') ? 1 : 0;
- else
- rootLoc = 2; // skip drive i.e. c:
+ if (separatorChar != '/') {
+ if (result[0] == '\\') {
+ rootLoc = (result.length > 1 && result[1] == '\\') ? 1 : 0;
+ } else {
+ rootLoc = 2; // skip drive i.e. c:
+ }
+ }
byte newResult[] = new byte[result.length + 1];
int newLength = 0, lastSlash = 0, foundDots = 0;
sepLocations[lastSlash] = rootLoc;
for (int i = 0; i <= result.length; i++) {
- if (i < rootLoc)
- newResult[newLength++] = result[i];
- else {
+ if (i < rootLoc) {
+ newResult[newLength++] = result[i];
+ } else {
if (i == result.length || result[i] == separatorChar) {
- if (i == result.length && foundDots == 0)
- break;
+ if (i == result.length && foundDots == 0) {
+ break;
+ }
if (foundDots == 1) {
/* Don't write anything, just reset and continue */
foundDots = 0;
@@ -528,21 +556,24 @@
continue;
}
/* Found some dots within text, write them out */
- if (foundDots > 0)
- for (int j = 0; j < foundDots; j++)
- newResult[newLength++] = (byte) '.';
+ if (foundDots > 0) {
+ for (int j = 0; j < foundDots; j++) {
+ newResult[newLength++] = (byte) '.';
+ }
+ }
newResult[newLength++] = result[i];
foundDots = 0;
}
}
// remove trailing slash
if (newLength > (rootLoc + 1)
- && newResult[newLength - 1] == separatorChar)
- newLength--;
+ && newResult[newLength - 1] == separatorChar) {
+ newLength--;
+ }
newResult[newLength] = 0;
newResult = getCanonImpl(newResult);
newLength = newResult.length;
- return org.apache.harmony.luni.util.Util.toString(newResult, 0, newLength);
+ return Util.toString(newResult, 0, newLength);
}
/**
@@ -582,16 +613,20 @@
*/
public String getParent() {
int length = path.length(), firstInPath = 0;
- if (separatorChar == '\\' && length > 2 && path.charAt(1) == ':')
- firstInPath = 2;
+ if (separatorChar == '\\' && length > 2 && path.charAt(1) == ':') {
+ firstInPath = 2;
+ }
int index = path.lastIndexOf(separatorChar);
- if (index == -1 && firstInPath > 0)
- index = 2;
- if (index == -1 || path.charAt(length - 1) == separatorChar)
- return null;
+ if (index == -1 && firstInPath > 0) {
+ index = 2;
+ }
+ if (index == -1 || path.charAt(length - 1) == separatorChar) {
+ return null;
+ }
if (path.indexOf(separatorChar) == index
- && path.charAt(firstInPath) == separatorChar)
- return path.substring(0, index + 1);
+ && path.charAt(firstInPath) == separatorChar) {
+ return path.substring(0, index + 1);
+ }
return path.substring(0, index);
}
@@ -604,8 +639,9 @@
*/
public File getParentFile() {
String tempParent = getParent();
- if (tempParent == null)
- return null;
+ if (tempParent == null) {
+ return null;
+ }
return new File(tempParent);
}
@@ -627,11 +663,12 @@
*
* @see #equals
*/
- public int hashCode() {
- if (caseSensitive)
- return path.hashCode() ^ 1234321;
- else
- return path.toLowerCase().hashCode() ^ 1234321;
+ @Override
+ public int hashCode() {
+ if (caseSensitive) {
+ return path.hashCode() ^ 1234321;
+ }
+ return path.toLowerCase().hashCode() ^ 1234321;
}
/**
@@ -646,7 +683,7 @@
* @see #getPath
*/
public boolean isAbsolute() {
- return isAbsoluteImpl(org.apache.harmony.luni.util.Util.getBytes(path));
+ return isAbsoluteImpl(Util.getBytes(path));
}
private native boolean isAbsoluteImpl(byte[] filePath);
@@ -662,11 +699,13 @@
* @see java.lang.SecurityManager#checkRead(FileDescriptor)
*/
public boolean isDirectory() {
- if (path.length() == 0)
- return false;
+ if (path.length() == 0) {
+ return false;
+ }
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return isDirectoryImpl(properPath(true));
}
@@ -683,11 +722,13 @@
* @see java.lang.SecurityManager#checkRead(FileDescriptor)
*/
public boolean isFile() {
- if (path.length() == 0)
- return false;
+ if (path.length() == 0) {
+ return false;
+ }
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return isFileImpl(properPath(true));
}
@@ -701,11 +742,13 @@
* otherwise.
*/
public boolean isHidden() {
- if (path.length() == 0)
- return false;
+ if (path.length() == 0) {
+ return false;
+ }
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return isHiddenImpl(properPath(true));
}
@@ -727,12 +770,14 @@
*/
public long lastModified() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
long result = lastModifiedImpl(properPath(true));
/* Temporary code to handle both return cases until natives fixed */
- if (result == -1 || result == 0)
- return 0;
+ if (result == -1 || result == 0) {
+ return 0;
+ }
return (result * 1000);
}
@@ -750,11 +795,12 @@
public boolean setLastModified(long time) {
if (time >= 0) {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkWrite(path);
+ if (security != null) {
+ security.checkWrite(path);
+ }
return (setLastModifiedImpl(properPath(true), time));
}
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg
+ throw new IllegalArgumentException(Msg
.getString("K006a")); //$NON-NLS-1$
}
@@ -769,8 +815,9 @@
*/
public boolean setReadOnly() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkWrite(path);
+ if (security != null) {
+ security.checkWrite(path);
+ }
return (setReadOnlyImpl(properPath(true)));
}
@@ -786,8 +833,9 @@
*/
public long length() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
+ if (security != null) {
+ security.checkRead(path);
+ }
return lengthImpl(properPath(true));
}
@@ -809,16 +857,20 @@
*/
public java.lang.String[] list() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
- if (!isDirectory())
- return null;
+ if (security != null) {
+ security.checkRead(path);
+ }
+ if (!isDirectory()) {
+ return null;
+ }
byte[][] implList = listImpl(properPath(true));
- if (implList == null)
- return new String[0];
+ if (implList == null) {
+ return new String[0];
+ }
String result[] = new String[implList.length];
- for (int index = 0; index < implList.length; index++)
- result[index] = org.apache.harmony.luni.util.Util.toString(implList[index]);
+ for (int index = 0; index < implList.length; index++) {
+ result[index] = Util.toString(implList[index]);
+ }
return result;
}
@@ -836,12 +888,14 @@
*/
public File[] listFiles() {
String[] tempNames = list();
- if (tempNames == null)
- return null;
+ if (tempNames == null) {
+ return null;
+ }
int resultLength = tempNames.length;
File results[] = new File[resultLength];
- for (int i = 0; i < resultLength; i++)
- results[i] = new File(this, tempNames[i]);
+ for (int i = 0; i < resultLength; i++) {
+ results[i] = new File(this, tempNames[i]);
+ }
return results;
}
@@ -865,12 +919,14 @@
*/
public File[] listFiles(FilenameFilter filter) {
String[] tempNames = list(filter);
- if (tempNames == null)
- return null;
+ if (tempNames == null) {
+ return null;
+ }
int resultLength = tempNames.length;
File results[] = new File[resultLength];
- for (int i = 0; i < resultLength; i++)
- results[i] = new File(this, tempNames[i]);
+ for (int i = 0; i < resultLength; i++) {
+ results[i] = new File(this, tempNames[i]);
+ }
return results;
}
@@ -893,23 +949,25 @@
*/
public File[] listFiles(FileFilter filter) {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
- if (!isDirectory())
- return null;
+ if (security != null) {
+ security.checkRead(path);
+ }
+ if (!isDirectory()) {
+ return null;
+ }
byte[][] implList = listImpl(properPath(true));
- if (implList == null)
- return new File[0];
- java.util.Vector<File> tempResult = new java.util.Vector<File>();
+ if (implList == null) {
+ return new File[0];
+ }
+ List<File> tempResult = new ArrayList<File>();
for (int index = 0; index < implList.length; index++) {
- String aName = org.apache.harmony.luni.util.Util.toString(implList[index]);
+ String aName = Util.toString(implList[index]);
File aFile = new File(this, aName);
- if (filter == null || filter.accept(aFile))
- tempResult.addElement(aFile);
+ if (filter == null || filter.accept(aFile)) {
+ tempResult.add(aFile);
+ }
}
- File[] result = new File[tempResult.size()];
- tempResult.copyInto(result);
- return result;
+ return tempResult.toArray(new File[tempResult.size()]);
}
/**
@@ -931,18 +989,22 @@
*/
public java.lang.String[] list(FilenameFilter filter) {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkRead(path);
- if (!isDirectory())
- return null;
+ if (security != null) {
+ security.checkRead(path);
+ }
+ if (!isDirectory()) {
+ return null;
+ }
byte[][] implList = listImpl(properPath(true));
- if (implList == null)
- return new String[0];
+ if (implList == null) {
+ return new String[0];
+ }
java.util.Vector<String> tempResult = new java.util.Vector<String>();
for (int index = 0; index < implList.length; index++) {
- String aName = org.apache.harmony.luni.util.Util.toString(implList[index]);
- if (filter == null || filter.accept(this, aName))
- tempResult.addElement(aName);
+ String aName = Util.toString(implList[index]);
+ if (filter == null || filter.accept(this, aName)) {
+ tempResult.addElement(aName);
+ }
}
String[] result = new String[tempResult.size()];
tempResult.copyInto(result);
@@ -963,8 +1025,9 @@
*/
public boolean mkdir() {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkWrite(path);
+ if (security != null) {
+ security.checkWrite(path);
+ }
return mkdirImpl(properPath(true));
}
@@ -981,17 +1044,20 @@
*/
public boolean mkdirs() {
/* If the terminal directory already exists, answer false */
- if (exists())
- return false;
+ if (exists()) {
+ return false;
+ }
/* If the receiver can be created, answer true */
- if (mkdir())
- return true;
+ if (mkdir()) {
+ return true;
+ }
String parentDir = getParent();
/* If there is no parent and we were not created, answer false */
- if (parentDir == null)
- return false;
+ if (parentDir == null) {
+ return false;
+ }
/* Otherwise, try to create a parent directory and then this directory */
return (new File(parentDir).mkdirs() && mkdir());
@@ -1013,10 +1079,11 @@
*/
public boolean createNewFile() throws IOException {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkWrite(path);
+ if (security != null) {
+ security.checkWrite(path);
+ }
if(0 == path.length()) {
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("KA012")); //$NON-NLS-1$
+ throw new IOException(Msg.getString("KA012")); //$NON-NLS-1$
}
int result = newFileImpl(properPath(true));
switch (result) {
@@ -1026,7 +1093,7 @@
case 3:
return false;
default:
- throw new IOException(org.apache.harmony.luni.util.Msg.getString("K01c2", path)); //$NON-NLS-1$
+ throw new IOException(Msg.getString("K01c2", path)); //$NON-NLS-1$
}
}
@@ -1080,7 +1147,7 @@
} while (!result.createNewFile());
return result;
}
- throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg
+ throw new IllegalArgumentException(Msg
.getString("K006b")); //$NON-NLS-1$
}
throw new NullPointerException();
@@ -1107,38 +1174,43 @@
* @return the proper path
*/
byte[] properPath(boolean internal) {
- if (properPath != null)
- return properPath;
- byte[] pathBytes = org.apache.harmony.luni.util.Util.getBytes(path);
- if (isAbsoluteImpl(pathBytes))
- return properPath = pathBytes;
+ if (properPath != null) {
+ return properPath;
+ }
+ byte[] pathBytes = Util.getBytes(path);
+ if (isAbsoluteImpl(pathBytes)) {
+ return properPath = pathBytes;
+ }
// Check security by getting user.dir when the path is not absolute
String userdir;
if (internal) {
userdir = AccessController.doPrivileged(new PriviAction<String>("user.dir")); //$NON-NLS-1$
- } else
- userdir = System.getProperty("user.dir"); //$NON-NLS-1$
- if ((properPath = properPathImpl(pathBytes)) != null)
- return properPath;
- if (path.length() == 0)
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir);
+ } else {
+ userdir = System.getProperty("user.dir"); //$NON-NLS-1$
+ }
+ if ((properPath = properPathImpl(pathBytes)) != null) {
+ return properPath;
+ }
+ if (path.length() == 0) {
+ return properPath = Util.getBytes(userdir);
+ }
int length = userdir.length();
if (path.charAt(0) == '\\') {
if (length > 1 && userdir.charAt(1) == ':') {
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir
+ return properPath = Util.getBytes(userdir
.substring(0, 2)
+ path);
}
if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir
+ return properPath = Util.getBytes(userdir
+ path.substring(1));
}
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir + path);
+ return properPath = Util.getBytes(userdir + path);
}
if (length > 0 && userdir.charAt(length - 1) == separatorChar) {
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir + path);
+ return properPath = Util.getBytes(userdir + path);
}
- return properPath = org.apache.harmony.luni.util.Util.getBytes(userdir + separator
+ return properPath = Util.getBytes(userdir + separator
+ path);
}
@@ -1174,7 +1246,8 @@
*
* @return a printable representation for the receiver.
*/
- public String toString() {
+ @Override
+ public String toString() {
return path.toString();
}
@@ -1188,13 +1261,14 @@
public URI toURI() {
String name = getAbsoluteName();
try {
- if (!name.startsWith("/")) // On Windows, absolute paths might not //$NON-NLS-1$
- // start with sep.
+ if (!name.startsWith("/")) {
+ // start with sep.
return new URI("file", null, //$NON-NLS-1$
new StringBuilder(name.length() + 1).append('/').append(
name).toString(), null, null);
- else if (name.startsWith("//")) //$NON-NLS-1$
- return new URI("file", name, null); // UNC path //$NON-NLS-1$
+ } else if (name.startsWith("//")) {
+ return new URI("file", name, null); // UNC path //$NON-NLS-1$
+ }
return new URI("file", null, name, null, null); //$NON-NLS-1$
} catch (URISyntaxException e) {
// this should never happen
@@ -1214,12 +1288,13 @@
*/
public URL toURL() throws java.net.MalformedURLException {
String name = getAbsoluteName();
- if (!name.startsWith("/")) // On Windows, absolute paths might not //$NON-NLS-1$
- // start with sep.
+ if (!name.startsWith("/")) {
+ // start with sep.
return new URL("file", "", -1, new StringBuilder(name.length() + 1) //$NON-NLS-1$ //$NON-NLS-2$
.append('/').append(name).toString(), null);
- else if (name.startsWith("//")) //$NON-NLS-1$
- return new URL("file:" + name); // UNC path //$NON-NLS-1$
+ } else if (name.startsWith("//")) {
+ return new URL("file:" + name); // UNC path //$NON-NLS-1$
+ }
return new URL("file", "", -1, name, null); //$NON-NLS-1$ //$NON-NLS-2$
}