Skip to content

Commit

Permalink
Remove usages from Java 7+
Browse files Browse the repository at this point in the history
  • Loading branch information
serega6531 committed May 9, 2020
1 parent 56dd15a commit 004b66b
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pcap4j-core/src/main/java/org/pcap4j/packet/TlsPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public TlsRecord getRecord() {

@Override
protected List<byte[]> getRawFields() {
List<byte[]> rawFields = new ArrayList<>();
List<byte[]> rawFields = new ArrayList<byte[]>();
rawFields.add(new byte[]{contentType.value()});
rawFields.add(ByteArrays.toByteArray(version.value()));
rawFields.add(ByteArrays.toByteArray(recordLength));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class AlertDescription extends NamedNumber<Byte, AlertDescription> {

private static final Map<Byte, AlertDescription> registry = new HashMap<>();
private static final Map<Byte, AlertDescription> registry = new HashMap<Byte, AlertDescription>();

// https://techcommunity.microsoft.com/t5/iis-support-blog/ssl-tls-alert-protocol-and-the-alert-codes/ba-p/377132

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@SuppressWarnings("unused")
public class AlertLevel extends NamedNumber<Byte, AlertLevel> {

private static final Map<Byte, AlertLevel> registry = new HashMap<>();
private static final Map<Byte, AlertLevel> registry = new HashMap<Byte, AlertLevel>();

public static final AlertLevel WARNING = new AlertLevel((byte) 1, "warning");
public static final AlertLevel FATAL = new AlertLevel((byte) 2, "fatal");
Expand All @@ -21,7 +21,11 @@ public AlertLevel(Byte value, String name) {
}

public static AlertLevel getInstance(Byte value) {
return registry.getOrDefault(value, ENCRYPTED_ALERT);
if (registry.containsKey(value)) {
return registry.get(value);
} else {
return ENCRYPTED_ALERT;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@SuppressWarnings("unused")
public class CipherSuite extends NamedNumber<Short, CipherSuite> {

private static final Map<Short, CipherSuite> registry = new HashMap<>();
private static final Map<Short, CipherSuite> registry = new HashMap<Short, CipherSuite>();

// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CompressionMethod extends NamedNumber<Byte, CompressionMethod> {
public static final CompressionMethod DEFLATE = new CompressionMethod((byte) 1, "Deflate");
public static final CompressionMethod LZS = new CompressionMethod((byte) 64, "LZS");

private static final Map<Byte, CompressionMethod> registry = new HashMap<>();
private static final Map<Byte, CompressionMethod> registry = new HashMap<Byte, CompressionMethod>();

static {
registry.put(NULL.value(), NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ContentType extends NamedNumber<Byte, ContentType> {
public static final ContentType APPLICATION_DATA = new ContentType((byte) 23, "Application Data");
public static final ContentType HEARTBEAT = new ContentType((byte) 24, "Heartbeat");

private static final Map<Byte, ContentType> registry = new HashMap<>();
private static final Map<Byte, ContentType> registry = new HashMap<Byte, ContentType>();

static {
registry.put(CHANGE_CIPHER_SPEC.value(), CHANGE_CIPHER_SPEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@SuppressWarnings("unused")
public class ExtensionType extends NamedNumber<Short, ExtensionType> {

private static final Map<Short, ExtensionType> registry = new HashMap<>();
private static final Map<Short, ExtensionType> registry = new HashMap<Short, ExtensionType>();

public static final ExtensionType SERVER_NAME = new ExtensionType((short) 0, "server_name");
public static final ExtensionType MAX_FRAGMENT_LENGTH = new ExtensionType((short) 1, "max_fragment_length");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@SuppressWarnings("unused")
public class HandshakeType extends NamedNumber<Byte, HandshakeType> {

private static final Map<Byte, HandshakeType> registry = new HashMap<>();
private static final Map<Byte, HandshakeType> registry = new HashMap<Byte, HandshakeType>();

// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml

Expand Down Expand Up @@ -42,7 +42,11 @@ public HandshakeType(Byte value, String name) {
}

public static HandshakeType getInstance(Byte value) {
return registry.getOrDefault(value, ENCRYPTED_HANDSHAKE_MESSAGE);
if (registry.containsKey(value)) {
return registry.get(value);
} else {
return ENCRYPTED_HANDSHAKE_MESSAGE;
}
}

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

public class HeartbeatMessageType extends NamedNumber<Byte, HeartbeatMessageType> {

private static final Map<Byte, HeartbeatMessageType> registry = new HashMap<>();
private static final Map<Byte, HeartbeatMessageType> registry = new HashMap<Byte, HeartbeatMessageType>();

public static final HeartbeatMessageType HEARTBEAT_REQUEST = new HeartbeatMessageType((byte) 1, "heartbeat_request");
public static final HeartbeatMessageType HEARTBEAT_RESPONSE = new HeartbeatMessageType((byte) 2, "heartbeat_response");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class KeyGroup extends NamedNumber<Short, KeyGroup> {

// https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml

private static final Map<Short, KeyGroup> registry = new HashMap<>();
private static final Map<Short, KeyGroup> registry = new HashMap<Short, KeyGroup>();

public static final KeyGroup RESERVED_GREASE_0 = new KeyGroup((short) 0, "Reserved (GREASE)");
public static final KeyGroup SECT163K1 = new KeyGroup((short) 1, "sect163k1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TlsVersion extends NamedNumber<Short, TlsVersion> {
public static final TlsVersion TLS_1_2 = new TlsVersion((short) 0x0303, "TLS 1.2");
public static final TlsVersion TLS_1_3 = new TlsVersion((short) 0x0304, "TLS 1.3");

private static final Map<Short, TlsVersion> registry = new HashMap<>();
private static final Map<Short, TlsVersion> registry = new HashMap<Short, TlsVersion>();

static {
registry.put(TLS_1_0.value(), TLS_1_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public abstract class KeyShareExtension extends TlsExtension {

private final List<KeyShareEntry> entries = new ArrayList<>();
private final List<KeyShareEntry> entries = new ArrayList<KeyShareEntry>();

public static KeyShareExtension newInstance(ExtensionType type, byte[] rawData, int offset,
short extensionLength, boolean client) {
Expand Down Expand Up @@ -45,7 +45,7 @@ public String toString() {
}

protected byte[] entriesToByteArray() {
List<byte[]> list = new ArrayList<>();
List<byte[]> list = new ArrayList<byte[]>();

for (KeyShareEntry entry : entries) {
list.add(entry.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum NamedCurve {

private final short value;

private static final Map<Short, NamedCurve> map = new HashMap<>();
private static final Map<Short, NamedCurve> map = new HashMap<Short, NamedCurve>();

NamedCurve(short value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum SignatureScheme {

private final short value;

private static final Map<Short, SignatureScheme> map = new HashMap<>();
private static final Map<Short, SignatureScheme> map = new HashMap<Short, SignatureScheme>();

SignatureScheme(short value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static CertificateHandshakeRecordContent newInstance(byte[] rawData, int

public CertificateHandshakeRecordContent(byte[] rawData, int offset, int length) {
this.certificatesLength = ByteArrays.getThreeBytesInt(rawData, CERTIFICATES_LENGTH_OFFSET + offset);
this.rawCertificates = new ArrayList<>();
this.rawCertificates = new ArrayList<byte[]>();

int cursor = CERTIFICATES_OFFSET + offset;
while (cursor < offset + length) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public String toString() {

@Override
public byte[] toByteArray() {
List<byte[]> list = new ArrayList<>();
List<byte[]> list = new ArrayList<byte[]>();

list.add(ByteArrays.threeBytesIntToByteArray(certificatesLength));
for (byte[] cert : rawCertificates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ClientHelloHandshakeRecordContent(byte[] rawData, int offset) {

this.cipherSuitesLength = ByteArrays.getShort(rawData, CIPHER_SUITES_LENGTH_OFFSET + sessionIdLength + offset);
int cipherSuitesAmount = cipherSuitesLength / SHORT_SIZE_IN_BYTES;
this.cipherSuites = new ArrayList<>(cipherSuitesAmount);
this.cipherSuites = new ArrayList<CipherSuite>(cipherSuitesAmount);

for (int i = 0; i < cipherSuitesAmount; i++) {
this.cipherSuites.add(CipherSuite.getInstance(ByteArrays.getShort(rawData,
Expand All @@ -63,7 +63,7 @@ private ClientHelloHandshakeRecordContent(byte[] rawData, int offset) {

this.compressionMethodsLength = ByteArrays.getByte(rawData,
COMPRESSION_METHODS_LENGTH_OFFSET + cipherSuitesLength + sessionIdLength + offset);
this.compressionMethods = new ArrayList<>(compressionMethodsLength);
this.compressionMethods = new ArrayList<CompressionMethod>(compressionMethodsLength);

for (byte i = 0; i < compressionMethodsLength; i++) {
this.compressionMethods.add(CompressionMethod.getInstance(ByteArrays.getByte(rawData,
Expand Down Expand Up @@ -124,7 +124,7 @@ public byte[] toByteArray() {
}

private byte[] cipherSuitesToByteArray() {
List<byte[]> list = new ArrayList<>();
List<byte[]> list = new ArrayList<byte[]>();

for (CipherSuite suite : cipherSuites) {
list.add(ByteArrays.toByteArray(suite.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void readCommonPart(byte[] rawData, int offset) {
}

protected void readExtensions(byte[] rawData, int offset, boolean client) {
extensions = new ArrayList<>(extensionsLength);
extensions = new ArrayList<TlsExtension>(extensionsLength);

int cursor = offset;
int extensionsEnd = cursor + extensionsLength;
Expand Down Expand Up @@ -107,7 +107,7 @@ protected byte[] commonPartToByteArray() {
}

protected byte[] extensionsToByteArray() {
List<byte[]> list = new ArrayList<>();
List<byte[]> list = new ArrayList<byte[]>();

list.add(ByteArrays.toByteArray(extensionsLength));
for (TlsExtension extension : extensions) {
Expand Down

0 comments on commit 004b66b

Please sign in to comment.