Skip to content

Commit

Permalink
refactor: refactor some code (#29)
Browse files Browse the repository at this point in the history
* refactor: rm unused code

* refactor: java doc

* refactor: remove unused code

* refactor: rpc module

* refactor: protocol module's unused code

* refactor: protocol module
  • Loading branch information
fengjiachun committed Feb 4, 2024
1 parent 28f5fd7 commit 2eddbd6
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 511 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package com.google.protobuf;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
* A {@code ByteString} helper, avoid some memory copying to improve performance.
*
Expand All @@ -31,43 +28,4 @@ public class ByteStringHelper {
public static ByteString wrap(byte[] bs) {
return ByteString.wrap(bs);
}

/**
* Wrap a byte array into a ByteString.
*
* @param bs the byte array
* @param offset read start offset in array
* @param len read data length
* @return the result byte string.
*/
public static ByteString wrap(byte[] bs, int offset, int len) {
return ByteString.wrap(bs, offset, len);
}

/**
* Wrap a byte buffer into a ByteString.
*/
public static ByteString wrap(ByteBuffer buf) {
return ByteString.wrap(buf);
}

/**
* Steal the byte[] from {@link ByteString}, if failed,
* then call {@link ByteString#toByteArray()}.
*
* @param byteString the byteString source data
* @return carried bytes
*/
public static byte[] sealByteArray(ByteString byteString) {
BytesStealer stealer = new BytesStealer();
try {
byteString.writeTo(stealer);
if (stealer.isValid()) {
return stealer.value();
}
} catch (IOException ignored) {
// ignored
}
return byteString.toByteArray();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void handle(sun.misc.Signal signal) {
h.handle(signal.getName());
}
} catch (Throwable t) {
LOG.error("Fail to handle signal: {}.", signal, t);
LOG.error("Failed to handle signal: {}.", signal, t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
*
* @author jiachun.fjc
*/
@SuppressWarnings("unused")
public class StringBuilderHelper {

private static final int MAX_BUF_SIZE;
private static final ThreadLocal<StringBuilderHolder> HOLDER_THREAD_LOCAL;

static {
MAX_BUF_SIZE = 1024 << 3; // 8k
MAX_BUF_SIZE = 1024 << 3; // 8k
HOLDER_THREAD_LOCAL = ThreadLocal.withInitial(StringBuilderHolder::new);
}

Expand All @@ -38,11 +37,6 @@ public static StringBuilder get() {
return holder.getStringBuilder();
}

public static void truncate() {
StringBuilderHolder holder = HOLDER_THREAD_LOCAL.get();
holder.truncate();
}

private static class StringBuilderHolder {

private StringBuilder buf = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public static boolean isNullOrEmpty(String str) {
/**
* Checks if a string is whitespace, empty ("") or null.
* <p>
* ``` java
* Strings.isBlank(null) = true
* Strings.isBlank("") = true
* Strings.isBlank(" ") = true
* Strings.isBlank("bob") = false
* Strings.isBlank(" bob ") = false
* ```
*/
public static boolean isBlank(String str) {
int strLen;
Expand All @@ -78,11 +80,13 @@ public static boolean isBlank(String str) {
/**
* Checks if a string is not empty (""), not null and not whitespace only.
* <p>
* ``` java
* Strings.isNotBlank(null) = false
* Strings.isNotBlank("") = false
* Strings.isNotBlank(" ") = false
* Strings.isNotBlank("bob") = true
* Strings.isNotBlank(" bob ") = true
* ```
*/
public static boolean isNotBlank(String str) {
return !isBlank(str);
Expand All @@ -93,12 +97,14 @@ public static boolean isNotBlank(String str) {
* <p>
* A null input String returns null.
* <p>
* ``` java
* Strings.split(null, *) = null
* Strings.split("", *) = []
* Strings.split("a.b.c", '.') = ["a", "b", "c"]
* Strings.split("a..b.c", '.') = ["a", "b", "c"]
* Strings.split("a:b:c", '.') = ["a:b:c"]
* Strings.split("a b c", ' ') = ["a", "b", "c"]
* ```
*/
public static String[] split(String str, char separator) {
return split(str, separator, false);
Expand All @@ -111,6 +117,7 @@ public static String[] split(String str, char separator) {
* <p>
* A null input String returns null.
* <p>
* ``` java
* Strings.split(null, *, true) = null
* Strings.split("", *, true) = []
* Strings.split("a.b.c", '.', true) = ["a", "b", "c"]
Expand All @@ -122,6 +129,7 @@ public static String[] split(String str, char separator) {
* Strings.split(" a b c", ' ', true) = ["", a", "b", "c"]
* Strings.split(" a b c", ' ', true) = ["", "", a", "b", "c"]
* Strings.split(" a b c ", ' ', true) = ["", a", "b", "c", ""]
* ```
*/
public static String[] split(String str, char separator, boolean preserveAllTokens) {
if (str == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,10 @@
* parse the values of the Java system properties.
*
*/
@SuppressWarnings("unused")
public final class SystemPropertyUtil {

private static final Logger LOG = LoggerFactory.getLogger(SystemPropertyUtil.class);

/**
* Returns {@code true} if and only if the system property
* with the specified {@code key} exists.
*/
public static boolean contains(String key) {
return get(key) != null;
}

/**
* Returns the value of the Java system property with the
* specified {@code key}, while falling back to {@code null}
Expand Down Expand Up @@ -155,6 +146,7 @@ public static int getInt(String key, int def) {
* {@code def} if there's no such property or if access to
* the specified property is not allowed.
*/
@SuppressWarnings("unused")
public static long getLong(String key, long def) {
String value = get(key);
if (value == null) {
Expand All @@ -178,6 +170,7 @@ public static long getLong(String key, long def) {
* Sets the value of the Java system property with the
* specified {@code key}
*/
@SuppressWarnings("unused")
public static Object setProperty(String key, String value) {
return System.getProperties().setProperty(key, value);
}
Expand Down
Loading

0 comments on commit 2eddbd6

Please sign in to comment.