Update TransitLock.java and UTFUtils.java
This commit is contained in:
parent
9950a4ceb1
commit
833c0f0c7c
@ -36,8 +36,10 @@ public class TransitLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void transit() {
|
public void transit() {
|
||||||
startTransit();
|
synchronized (synchronization) {
|
||||||
endTransit();
|
startTransit();
|
||||||
|
endTransit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTransit() {
|
public void startTransit() {
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
package org.warp.commonutils.serialization;
|
package org.warp.commonutils.serialization;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class UTFUtils {
|
public class UTFUtils {
|
||||||
public static final void writeUTF(DataOutputStream out, String utf) throws IOException {
|
public static final void writeUTF(DataOutput out, String utf) throws IOException {
|
||||||
byte[] bytes = utf.getBytes(StandardCharsets.UTF_8);
|
byte[] bytes = utf.getBytes(StandardCharsets.UTF_8);
|
||||||
out.writeInt(bytes.length);
|
out.writeInt(bytes.length);
|
||||||
out.write(bytes);
|
out.write(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String readUTF(DataInputStream in) throws IOException {
|
public static final String readUTF(DataInput in) throws IOException {
|
||||||
int len = in.readInt();
|
int len = in.readInt();
|
||||||
return new String(in.readNBytes(len), StandardCharsets.UTF_8);
|
byte[] data = new byte[len];
|
||||||
|
in.readFully(data, 0, len);
|
||||||
|
return new String(data, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user