mirror of
https://github.com/corda/corda.git
synced 2025-02-01 16:58:27 +00:00
Merge pull request #409 from marcinolawski/master
Added missing methods to ByteArrayOutputStream, Modifier and UTFDataFormatException.
This commit is contained in:
commit
f05f116c3f
@ -13,7 +13,8 @@ package java.io;
|
|||||||
public class ByteArrayOutputStream extends OutputStream {
|
public class ByteArrayOutputStream extends OutputStream {
|
||||||
private static final int BufferSize = 32;
|
private static final int BufferSize = 32;
|
||||||
|
|
||||||
private Cell chain;
|
private Cell firstCell;
|
||||||
|
private Cell curCell;
|
||||||
private int length;
|
private int length;
|
||||||
private byte[] buffer;
|
private byte[] buffer;
|
||||||
private int position;
|
private int position;
|
||||||
@ -25,7 +26,8 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
chain = null;
|
firstCell = null;
|
||||||
|
curCell = null;
|
||||||
length = 0;
|
length = 0;
|
||||||
buffer = null;
|
buffer = null;
|
||||||
position = 0;
|
position = 0;
|
||||||
@ -69,19 +71,30 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||||||
position += length;
|
position += length;
|
||||||
} else {
|
} else {
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
chain = new Cell(copy(b, offset, length), 0, length, chain);
|
chainCell( new Cell(copy(b, offset, length), 0, length) );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.length += length;
|
this.length += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void chainCell(Cell cell){
|
||||||
|
if (curCell == null){
|
||||||
|
firstCell = cell;
|
||||||
|
curCell = cell;
|
||||||
|
}else{
|
||||||
|
curCell.next = cell;
|
||||||
|
curCell = cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void flushBuffer() {
|
private void flushBuffer() {
|
||||||
if (position > 0) {
|
if (position > 0) {
|
||||||
byte[] b = buffer;
|
byte[] b = buffer;
|
||||||
int p = position;
|
int p = position;
|
||||||
buffer = null;
|
buffer = null;
|
||||||
position = 0;
|
position = 0;
|
||||||
chain = new Cell(b, 0, p, chain);
|
|
||||||
|
chainCell( new Cell(b, 0, p) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,15 +102,28 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||||||
flushBuffer();
|
flushBuffer();
|
||||||
|
|
||||||
byte[] array = new byte[length];
|
byte[] array = new byte[length];
|
||||||
int index = length;
|
int pos = 0;
|
||||||
for (Cell c = chain; c != null; c = c.next) {
|
for (Cell c = firstCell; c != null; c = c.next) {
|
||||||
int start = index - c.length;
|
System.arraycopy(c.array, c.offset, array, pos, c.length);
|
||||||
System.arraycopy(c.array, c.offset, array, start, c.length);
|
pos += c.length;
|
||||||
index = start;
|
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void writeTo(OutputStream out) throws IOException {
|
||||||
|
if (length==0) return;
|
||||||
|
|
||||||
|
if (out == null){
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
|
||||||
|
flushBuffer();
|
||||||
|
|
||||||
|
for (Cell c = firstCell; c != null; c = c.next) {
|
||||||
|
out.write(c.array, c.offset, c.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new String(toByteArray());
|
return new String(toByteArray());
|
||||||
@ -111,13 +137,12 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||||||
public byte[] array;
|
public byte[] array;
|
||||||
public int offset;
|
public int offset;
|
||||||
public int length;
|
public int length;
|
||||||
public Cell next;
|
public Cell next = null;
|
||||||
|
|
||||||
public Cell(byte[] array, int offset, int length, Cell next) {
|
public Cell(byte[] array, int offset, int length) {
|
||||||
this.array = array;
|
this.array = array;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.next = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
classpath/java/io/UTFDataFormatException.java
Normal file
21
classpath/java/io/UTFDataFormatException.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* Copyright (c) 2008-2015, Avian Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice appear
|
||||||
|
in all copies.
|
||||||
|
|
||||||
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
|
details. */
|
||||||
|
|
||||||
|
package java.io;
|
||||||
|
|
||||||
|
public class UTFDataFormatException extends IOException {
|
||||||
|
public UTFDataFormatException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UTFDataFormatException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ public final class Modifier {
|
|||||||
public static boolean isProtected(int v) { return (v & PROTECTED) != 0; }
|
public static boolean isProtected(int v) { return (v & PROTECTED) != 0; }
|
||||||
public static boolean isStatic (int v) { return (v & STATIC) != 0; }
|
public static boolean isStatic (int v) { return (v & STATIC) != 0; }
|
||||||
public static boolean isFinal (int v) { return (v & FINAL) != 0; }
|
public static boolean isFinal (int v) { return (v & FINAL) != 0; }
|
||||||
|
public static boolean isTransient(int v) { return (v & TRANSIENT) != 0; }
|
||||||
public static boolean isSuper (int v) { return (v & SUPER) != 0; }
|
public static boolean isSuper (int v) { return (v & SUPER) != 0; }
|
||||||
public static boolean isNative (int v) { return (v & NATIVE) != 0; }
|
public static boolean isNative (int v) { return (v & NATIVE) != 0; }
|
||||||
public static boolean isAbstract (int v) { return (v & ABSTRACT) != 0; }
|
public static boolean isAbstract (int v) { return (v & ABSTRACT) != 0; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user