aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/com/android/io
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-01-05 15:47:09 -0800
committerTor Norbye <tnorbye@google.com>2012-01-05 21:25:47 -0800
commit581ca2e75fd638f6e95570ac54ff9e6b7b7cde84 (patch)
tree130b1ad476c0230db414fdd03cfe4efaac7dadbc /common/src/com/android/io
parentc000db8d112f4143249fa79a24c6ddb2ffc122f3 (diff)
downloadsdk-581ca2e75fd638f6e95570ac54ff9e6b7b7cde84.zip
sdk-581ca2e75fd638f6e95570ac54ff9e6b7b7cde84.tar.gz
sdk-581ca2e75fd638f6e95570ac54ff9e6b7b7cde84.tar.bz2
Extract positional XML parser into common and fix encoding issues
The XML DOM parser used by the lint CLI driver (which tracks positions) is needed outside of lint, so pull it out of the lint/cli project, and refactor it such that it does not directly reference the lint Position APIs (but can utilize them when subclassed in lint). In addition, handle non-UTF-8 file encodings. XML files can be encoded in other character sets, and can specify this via the encoding attribute in the XML prologue. Until now, the CLI lint runner would just read the XML file contents in using the default encoding and parse this. Now there's a new utility method which takes a byte[] and infers the desired encoding and uses that to convert the byte[] into a string using the correct encoding. (We can't just pass an InputStream and let the SAX parser handle this on its own because the XML parser needs to access the character stream in order to assign correct node offsets.) This code now also handles the byte order mark more cleanly. There are some new unit tests too to check the new encoding, BOM and offset handling. Change-Id: Ib0badbbe72172e3408c6d5af2413be51280a7724
Diffstat (limited to 'common/src/com/android/io')
-rw-r--r--common/src/com/android/io/FileWrapper.java7
-rw-r--r--common/src/com/android/io/FolderWrapper.java8
2 files changed, 15 insertions, 0 deletions
diff --git a/common/src/com/android/io/FileWrapper.java b/common/src/com/android/io/FileWrapper.java
index 2859c0d..84a1f3e 100644
--- a/common/src/com/android/io/FileWrapper.java
+++ b/common/src/com/android/io/FileWrapper.java
@@ -85,6 +85,7 @@ public class FileWrapper extends File implements IAbstractFile {
super(uri);
}
+ @Override
public InputStream getContents() throws StreamException {
try {
return new FileInputStream(this);
@@ -93,6 +94,7 @@ public class FileWrapper extends File implements IAbstractFile {
}
}
+ @Override
public void setContents(InputStream source) throws StreamException {
FileOutputStream fos = null;
try {
@@ -116,6 +118,7 @@ public class FileWrapper extends File implements IAbstractFile {
}
}
+ @Override
public OutputStream getOutputStream() throws StreamException {
try {
return new FileOutputStream(this);
@@ -124,10 +127,12 @@ public class FileWrapper extends File implements IAbstractFile {
}
}
+ @Override
public PreferredWriteMode getPreferredWriteMode() {
return PreferredWriteMode.OUTPUTSTREAM;
}
+ @Override
public String getOsLocation() {
return getAbsolutePath();
}
@@ -137,10 +142,12 @@ public class FileWrapper extends File implements IAbstractFile {
return isFile();
}
+ @Override
public long getModificationStamp() {
return lastModified();
}
+ @Override
public IAbstractFolder getParentFolder() {
String p = this.getParent();
if (p == null) {
diff --git a/common/src/com/android/io/FolderWrapper.java b/common/src/com/android/io/FolderWrapper.java
index 26ed9cf..c29c934 100644
--- a/common/src/com/android/io/FolderWrapper.java
+++ b/common/src/com/android/io/FolderWrapper.java
@@ -81,6 +81,7 @@ public class FolderWrapper extends File implements IAbstractFolder {
super(file.getAbsolutePath());
}
+ @Override
public IAbstractResource[] listMembers() {
File[] files = listFiles();
final int count = files == null ? 0 : files.length;
@@ -100,8 +101,10 @@ public class FolderWrapper extends File implements IAbstractFolder {
return afiles;
}
+ @Override
public boolean hasFile(final String name) {
String[] match = list(new FilenameFilter() {
+ @Override
public boolean accept(IAbstractFolder dir, String filename) {
return name.equals(filename);
}
@@ -110,14 +113,17 @@ public class FolderWrapper extends File implements IAbstractFolder {
return match.length > 0;
}
+ @Override
public IAbstractFile getFile(String name) {
return new FileWrapper(this, name);
}
+ @Override
public IAbstractFolder getFolder(String name) {
return new FolderWrapper(this, name);
}
+ @Override
public IAbstractFolder getParentFolder() {
String p = this.getParent();
if (p == null) {
@@ -126,6 +132,7 @@ public class FolderWrapper extends File implements IAbstractFolder {
return new FolderWrapper(p);
}
+ @Override
public String getOsLocation() {
return getAbsolutePath();
}
@@ -135,6 +142,7 @@ public class FolderWrapper extends File implements IAbstractFolder {
return isDirectory();
}
+ @Override
public String[] list(FilenameFilter filter) {
File[] files = listFiles();
if (files != null && files.length > 0) {