mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
Merge remote-tracking branch 'git/master'
This commit is contained in:
commit
6153a5c83b
@ -281,6 +281,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid)
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) {
|
||||
TerminateProcess(reinterpret_cast<HANDLE>(pid), 1);
|
||||
}
|
||||
|
||||
Locale getLocale() {
|
||||
const char* lang = "";
|
||||
const char* reg = "";
|
||||
@ -468,6 +473,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv*, jclass, jlong pid, jlong)
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) {
|
||||
kill((pid_t)pid, SIGTERM);
|
||||
}
|
||||
|
||||
Locale getLocale() {
|
||||
Locale fallback;
|
||||
|
||||
|
@ -46,8 +46,7 @@ public class BufferedReader extends Reader {
|
||||
sb.append(buffer, position, i - position);
|
||||
position = i + 1;
|
||||
if(i+1 < limit && buffer[i+1] == '\n') {
|
||||
position = i + 1;
|
||||
return sb.toString();
|
||||
position = i + 2;
|
||||
}
|
||||
return sb.toString();
|
||||
} else if (buffer[i] == '\n') {
|
||||
|
@ -56,7 +56,7 @@ public abstract class InputStream {
|
||||
}
|
||||
|
||||
public void reset() throws IOException {
|
||||
// ignore
|
||||
throw new IOException("mark/reset not supported");
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
|
@ -12,16 +12,21 @@ package java.io;
|
||||
|
||||
public class RandomAccessFile {
|
||||
private long peer;
|
||||
private long length;
|
||||
private File file;
|
||||
private long position = 0;
|
||||
|
||||
private long length;
|
||||
|
||||
public RandomAccessFile(String name, String mode)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
if (! mode.equals("r")) throw new IllegalArgumentException();
|
||||
file = new File(name);
|
||||
open();
|
||||
}
|
||||
|
||||
private void open() throws FileNotFoundException {
|
||||
long[] result = new long[2];
|
||||
open(name, result);
|
||||
open(file.getPath(), result);
|
||||
peer = result[0];
|
||||
length = result[1];
|
||||
}
|
||||
@ -29,7 +34,15 @@ public class RandomAccessFile {
|
||||
private static native void open(String name, long[] result)
|
||||
throws FileNotFoundException;
|
||||
|
||||
private void refresh() throws IOException {
|
||||
if (file.length() != length) {
|
||||
close();
|
||||
open();
|
||||
}
|
||||
}
|
||||
|
||||
public long length() throws IOException {
|
||||
refresh();
|
||||
return length;
|
||||
}
|
||||
|
||||
@ -38,7 +51,7 @@ public class RandomAccessFile {
|
||||
}
|
||||
|
||||
public void seek(long position) throws IOException {
|
||||
if (position < 0 || position > length) throw new IOException();
|
||||
if (position < 0 || position > length()) throw new IOException();
|
||||
|
||||
this.position = position;
|
||||
}
|
||||
@ -50,12 +63,16 @@ public class RandomAccessFile {
|
||||
|
||||
if (length == 0) return;
|
||||
|
||||
if (position + length > this.length) throw new EOFException();
|
||||
if (position + length > this.length) {
|
||||
if (position + length > length()) throw new EOFException();
|
||||
}
|
||||
|
||||
if (offset < 0 || offset + length > buffer.length)
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
|
||||
copy(peer, position, buffer, offset, length);
|
||||
|
||||
position += length;
|
||||
}
|
||||
|
||||
private static native void copy(long peer, long position, byte[] buffer,
|
||||
|
@ -122,6 +122,8 @@ public class Runtime {
|
||||
|
||||
private static native void load(String name, boolean mapName);
|
||||
|
||||
private static native void kill(long pid);
|
||||
|
||||
public native void gc();
|
||||
|
||||
public native void exit(int code);
|
||||
@ -147,7 +149,7 @@ public class Runtime {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
throw new RuntimeException("not implemented");
|
||||
kill(pid);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
|
@ -15,45 +15,50 @@ public abstract class Buffer {
|
||||
protected int position;
|
||||
protected int limit;
|
||||
|
||||
public int limit() {
|
||||
public final int limit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public int remaining() {
|
||||
public final int remaining() {
|
||||
return limit-position;
|
||||
}
|
||||
|
||||
public int position() {
|
||||
public final int position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public int capacity() {
|
||||
public final int capacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public Buffer limit(int newLimit) {
|
||||
public final Buffer limit(int newLimit) {
|
||||
limit = newLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Buffer position(int newPosition) {
|
||||
public final Buffer position(int newPosition) {
|
||||
position = newPosition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasRemaining() {
|
||||
public final boolean hasRemaining() {
|
||||
return remaining() > 0;
|
||||
}
|
||||
|
||||
public Buffer clear() {
|
||||
public final Buffer clear() {
|
||||
position = 0;
|
||||
limit = capacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Buffer flip() {
|
||||
public final Buffer flip() {
|
||||
limit = position;
|
||||
position = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final Buffer rewind() {
|
||||
position = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
31
test/Processes.java
Normal file
31
test/Processes.java
Normal file
@ -0,0 +1,31 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class Processes {
|
||||
public static void main(String[] args) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
final Process p = Runtime.getRuntime().exec("sleep 10");
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch(InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
p.destroy();
|
||||
}
|
||||
}.start();
|
||||
try {
|
||||
p.waitFor();
|
||||
} catch(InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
long stop = System.currentTimeMillis();
|
||||
if(stop - start > 5000) {
|
||||
throw new RuntimeException("test failed; we didn't kill the process...");
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user