Update TransitLock.java and UTFUtils.java

This commit is contained in:
Andrea Cavalli 2021-01-27 03:04:35 +01:00
parent 9950a4ceb1
commit 833c0f0c7c
2 changed files with 11 additions and 7 deletions

View File

@ -36,8 +36,10 @@ public class TransitLock {
}
public void transit() {
startTransit();
endTransit();
synchronized (synchronization) {
startTransit();
endTransit();
}
}
public void startTransit() {

View File

@ -1,19 +1,21 @@
package org.warp.commonutils.serialization;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
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);
out.writeInt(bytes.length);
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();
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);
}
}