Skip to content

Commit

Permalink
issue #103 Modernise
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed May 31, 2020
1 parent ba6f6a8 commit 11ed19d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;

Expand Down Expand Up @@ -93,9 +94,9 @@ public String toString() {
return sb.toString();
}

public void printStatistics(OutputStream stream) {;
public void printStatistics(OutputStream stream) {
try {
stream.write(toString().getBytes("UTF-8"));
stream.write(toString().getBytes(StandardCharsets.UTF_8));
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import org.simpledbm.common.api.exception.SimpleDBMException;
Expand Down Expand Up @@ -69,13 +70,8 @@ public ByteString() {
}

public ByteString(String s) {
try {
this.s = s;
bytes = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SimpleDBMException(new MessageInstance(
illegalEncodingMessage), e);
}
this.s = s;
bytes = s.getBytes(StandardCharsets.UTF_8);
}

public ByteString(byte[] bytes) {
Expand Down Expand Up @@ -103,15 +99,10 @@ public String toString() {
if (s != null) {
return s;
}
try {
synchronized (this) {
if (null == s) {
s = new String(bytes, "UTF-8");
}
synchronized (this) {
if (null == s) {
s = new String(bytes, StandardCharsets.UTF_8);
}
} catch (UnsupportedEncodingException e) {
throw new SimpleDBMException(new MessageInstance(
illegalEncodingMessage), e);
}
return s;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Properties getResourceAsProperties(String name) throws IOException {
*/
public Object invokeMethod(Class<?> cl, Object instance, String methodName,
Object param) throws Throwable {
Class<? extends Object> paramClass;
Class<?> paramClass;
if (param instanceof Integer)
paramClass = Integer.TYPE;
else if (param instanceof Long)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.simpledbm.common.util;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.simpledbm.common.api.exception.SimpleDBMException;
import org.simpledbm.common.util.mcat.Message;
Expand All @@ -51,7 +52,7 @@ public class StringUtils {

public static byte[] getUTF8Bytes(String s) {
try {
return s.getBytes(Charset.forName("UTF-8"));
return s.getBytes(StandardCharsets.UTF_8);
}
catch (Exception e) {
throw new SimpleDBMException(new MessageInstance(m_EU0001));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.simpledbm.network.client.impl;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import org.simpledbm.common.api.registry.Storable;
import org.simpledbm.common.api.tx.IsolationMode;
Expand Down Expand Up @@ -62,11 +63,7 @@ public SessionImpl(SessionManager sessionManager, int sessionId) {
String getError(Response response) {
byte[] data = response.getData().array();
String msg;
try {
msg = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
msg = "Error message could not be decoded";
}
msg = new String(data, StandardCharsets.UTF_8);
return msg;
}

Expand Down Expand Up @@ -119,4 +116,4 @@ public int getSessionId() {
Response sendMessage(int requestCode, Storable message) {
return sessionManager.sendMessage(sessionId, requestCode, message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

import org.simpledbm.common.api.exception.SimpleDBMException;
import org.simpledbm.common.util.mcat.Message;
Expand Down Expand Up @@ -79,11 +80,7 @@ public class ConnectionImpl implements Connection {
private String getError(Response response) {
byte[] data = response.getData().array();
String msg;
try {
msg = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
msg = "Error message could not be decoded";
}
msg = new String(data, StandardCharsets.UTF_8);
return msg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
Expand Down Expand Up @@ -196,11 +197,7 @@ public void onStart() {
private void setError(Response response, int statusCode, String message) {
response.setStatusCode(statusCode);
byte[] bytes;
try {
bytes = message.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SimpleDBMException(new MessageInstance(encodingError), e);
}
bytes = message.getBytes(StandardCharsets.UTF_8);
ByteBuffer data = ByteBuffer.wrap(bytes);
data.limit(bytes.length);
response.setData(data);
Expand Down Expand Up @@ -235,11 +232,7 @@ void setError(Response response, int statusCode, String message, Throwable e) {
}
} while (e != null);
byte[] bytes;
try {
bytes = sb.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new SimpleDBMException(new MessageInstance(encodingError), e1);
}
bytes = sb.toString().getBytes(StandardCharsets.UTF_8);
ByteBuffer data = ByteBuffer.wrap(bytes);
data.limit(bytes.length);
response.setData(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public final class NewReadWriteUpdateLatch implements Latch {
* @author Dibyendu Majumdar
*/
enum ReleaseAction {
RELEASE, DOWNGRADE;
RELEASE, DOWNGRADE
}

/**
Expand All @@ -137,7 +137,7 @@ public enum LockStatus {
}

static enum LockRequestStatus {
GRANTED, CONVERTING, WAITING, DENIED;
GRANTED, CONVERTING, WAITING, DENIED
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.nio.ByteBuffer;

import org.simpledbm.common.util.TypeSize;
Expand Down Expand Up @@ -151,14 +152,14 @@ public String getString() {
@Override
public void setInt(Integer integer) {
d = new BigDecimal(integer);
d = d.setScale(getType().getScale(), BigDecimal.ROUND_HALF_UP);
d = d.setScale(getType().getScale(), RoundingMode.HALF_UP);
setValue();
}

@Override
public void setString(String string) {
d = new BigDecimal(string);
d = d.setScale(getType().getScale(), BigDecimal.ROUND_HALF_UP);
d = d.setScale(getType().getScale(), RoundingMode.HALF_UP);
setValue();
}

Expand Down

0 comments on commit 11ed19d

Please sign in to comment.