package com.basic.security.manager;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
public class ByteArrayManager {
|
|
public static Map<Integer, List<byte[]>> byteArrayListMap = new HashMap<>();
|
public static int lengthIndex = 0;
|
|
public static synchronized byte[] newBytes(int length) {
|
byte[] newBytes = null;
|
try {
|
List<byte[]> byteArrayList = byteArrayListMap.get(length);
|
if (byteArrayList == null) {
|
byteArrayList = new ArrayList<>();
|
for (int i = 0; i < 10; i++) {
|
byte[] bytes = new byte[length];
|
byteArrayList.add(bytes);
|
}
|
byteArrayListMap.put(length, byteArrayList);
|
}
|
lengthIndex = lengthIndex % byteArrayList.size();
|
newBytes = byteArrayList.get(lengthIndex);
|
lengthIndex++;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (newBytes == null) {
|
newBytes = new byte[length];
|
}
|
return newBytes;
|
}
|
}
|