mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
quick sketch of java/io/*
This commit is contained in:
@ -130,6 +130,30 @@ public final class String implements Comparable<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
byte[] b = new byte[length];
|
||||
getBytes(0, length, b, 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
public void getBytes(int srcOffset, int srcLength,
|
||||
byte[] dst, int dstOffset)
|
||||
{
|
||||
if (srcOffset + srcLength > length) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
if (data instanceof char[]) {
|
||||
char[] src = (char[]) data;
|
||||
for (int i = 0; i < srcLength; ++i) {
|
||||
dst[i + dstOffset] = (byte) src[i + offset + srcOffset];
|
||||
}
|
||||
} else {
|
||||
byte[] src = (byte[]) data;
|
||||
System.arraycopy(src, offset + srcOffset, dst, dstOffset, srcLength);
|
||||
}
|
||||
}
|
||||
|
||||
public void getChars(int srcOffset, int srcLength,
|
||||
char[] dst, int dstOffset)
|
||||
{
|
||||
|
@ -5,17 +5,6 @@
|
||||
#undef JNIEXPORT
|
||||
#define JNIEXPORT __attribute__ ((visibility("default")))
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_java_lang_System_00024Output_print(JNIEnv* e, jobject, jstring s)
|
||||
{
|
||||
jboolean isCopy;
|
||||
const char* chars = e->GetStringUTFChars(s, &isCopy);
|
||||
if (chars) {
|
||||
printf("%s", chars);
|
||||
}
|
||||
e->ReleaseStringUTFChars(s, chars);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_java_lang_System_getProperty(JNIEnv* e, jstring key)
|
||||
{
|
||||
|
@ -1,13 +1,27 @@
|
||||
package java.lang;
|
||||
|
||||
public abstract class System {
|
||||
public static final Output out = new Output();
|
||||
public static final Output err = out;
|
||||
import java.io.PrintStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileDescriptor;
|
||||
|
||||
public abstract class System {
|
||||
static {
|
||||
loadLibrary("natives");
|
||||
}
|
||||
|
||||
public static final PrintStream out = new PrintStream
|
||||
(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
|
||||
|
||||
public static final PrintStream err = new PrintStream
|
||||
(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
|
||||
|
||||
public static final InputStream in
|
||||
= new BufferedInputStream(new FileInputStream(FileDescriptor.in));
|
||||
|
||||
public static native void arraycopy(Object src, int srcOffset, Object dst,
|
||||
int dstOffset, int length);
|
||||
|
||||
@ -26,13 +40,4 @@ public abstract class System {
|
||||
public static void exit(int code) {
|
||||
Runtime.getRuntime().exit(code);
|
||||
}
|
||||
|
||||
public static class Output {
|
||||
public synchronized native void print(String s);
|
||||
|
||||
public synchronized void println(String s) {
|
||||
print(s);
|
||||
print(getProperty("line.separator"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user