Merge remote branch 'oss/master' into jdk7

This commit is contained in:
Joel Dice 2012-05-04 20:24:27 -06:00
commit 4a4b82d959
4 changed files with 85 additions and 13 deletions

View File

@ -16,6 +16,7 @@ public class FileInputStream extends InputStream {
// }
private int fd;
private int remaining;
public FileInputStream(FileDescriptor fd) {
this.fd = fd.value;
@ -23,12 +24,17 @@ public class FileInputStream extends InputStream {
public FileInputStream(String path) throws IOException {
fd = open(path);
remaining = (int) new File(path).length();
}
public FileInputStream(File file) throws IOException {
this(file.getPath());
}
public int available() throws IOException {
return remaining;
}
private static native int open(String path) throws IOException;
private static native int read(int fd) throws IOException;
@ -39,7 +45,11 @@ public class FileInputStream extends InputStream {
public static native void close(int fd) throws IOException;
public int read() throws IOException {
return read(fd);
int c = read(fd);
if (c >= 0 && remaining > 0) {
-- remaining;
}
return c;
}
public int read(byte[] b, int offset, int length) throws IOException {
@ -51,7 +61,11 @@ public class FileInputStream extends InputStream {
throw new ArrayIndexOutOfBoundsException();
}
return read(fd, b, offset, length);
int c = read(fd, b, offset, length);
if (c > 0 && remaining > 0) {
remaining -= c;
}
return c;
}
public void close() throws IOException {

View File

@ -86,7 +86,7 @@ public class ZipFile {
}
public InputStream getInputStream(ZipEntry entry) throws IOException {
int pointer = ((MyEntry) entry).pointer();
final int pointer = ((MyEntry) entry).pointer();
int method = compressionMethod(window, pointer);
int size = compressedSize(window, pointer);
InputStream in = new MyInputStream(file, fileData(window, pointer), size);
@ -99,7 +99,35 @@ public class ZipFile {
return in;
case Deflated:
return new InflaterInputStream(in, new Inflater(true));
return new InflaterInputStream(in, new Inflater(true)) {
int remaining = uncompressedSize(window, pointer);
public int read() throws IOException {
int c = super.read();
if (c >= 0) {
-- remaining;
}
return c;
}
public int read(byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length);
}
public int read(byte[] buffer, int offset, int length)
throws IOException
{
int c = super.read(buffer, offset, length);
if (c > 0) {
remaining -= c;
}
return c;
}
public int available() {
return remaining;
}
};
default:
throw new IOException();

View File

@ -1293,15 +1293,17 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
class MyCompilationHandler : public Processor::CompilationHandler {
public:
virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* class_, const char* name, const char* spec) {
size_t classLen = strlen(class_);
size_t nameLen = strlen(name);
size_t specLen = strlen(spec);
char* completeName = (char*)malloc(classLen + nameLen + specLen + 2);
sprintf(completeName, "%s.%s%s", class_, name, spec);
uint64_t offset = reinterpret_cast<uint64_t>(code) - codeOffset;
symbols.add(SymbolInfo(offset, completeName));
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
if (class_ and name and spec) {
size_t classLen = strlen(class_);
size_t nameLen = strlen(name);
size_t specLen = strlen(spec);
char* completeName = (char*)malloc(classLen + nameLen + specLen + 2);
sprintf(completeName, "%s.%s%s", class_, name, spec);
uint64_t offset = reinterpret_cast<uint64_t>(code) - codeOffset;
symbols.add(SymbolInfo(offset, completeName));
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
}
}
virtual void dispose() {}

View File

@ -1,4 +1,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Files {
private static void expect(boolean v) {
@ -46,6 +48,32 @@ public class Files {
expect(! f.createNewFile());
f.delete();
}
{ File f = new File("test.txt");
FileOutputStream out = new FileOutputStream(f);
try {
byte[] message = "hello, world!\n".getBytes();
out.write(message);
out.close();
FileInputStream in = new FileInputStream(f);
try {
expect(in.available() == message.length);
for (int i = 0; i < message.length; ++i) {
in.read();
expect(in.available() == message.length - i - 1);
}
expect(in.read() == -1);
expect(in.available() == 0);
} finally {
in.close();
}
} finally {
f.delete();
}
}
}
}