@Test public void testSerializeNullableString() { String randomString = TestUtils.getRandomString(10); ByteBuffer outputBuffer = ByteBuffer.allocate(4 + randomString.getBytes().length); Utils.serializeNullableString(outputBuffer, randomString); outputBuffer.flip(); int length = outputBuffer.getInt(); assertEquals("Input and output string lengths don't match ", randomString.getBytes().length, length); byte[] output = new byte[length]; outputBuffer.get(output); assertFalse("Output buffer shouldn't have any remaining, but has " + outputBuffer.remaining() + " bytes", outputBuffer.hasRemaining()); String outputString = new String(output); assertEquals("Input and output strings don't match", randomString, outputString); randomString = null; outputBuffer = ByteBuffer.allocate(4); Utils.serializeNullableString(outputBuffer, randomString); outputBuffer.flip(); length = outputBuffer.getInt(); assertEquals("Input and output string lengths don't match", 0, length); output = new byte[length]; outputBuffer.get(output); assertFalse("Output buffer shouldn't have any remaining, but has " + outputBuffer.remaining() + " bytes", outputBuffer.hasRemaining()); outputString = new String(output); assertEquals("Output string \"" + outputString + "\" expected to be empty", outputString, ""); }
public static void serializeNullableString(ByteBuffer outputBuffer, String value) { if (value == null) { outputBuffer.putInt(0); } else { serializeString(outputBuffer, value, Charset.defaultCharset()); } }
Utils { public static void serializeNullableString(ByteBuffer outputBuffer, String value) { if (value == null) { outputBuffer.putInt(0); } else { serializeString(outputBuffer, value, Charset.defaultCharset()); } } }
Utils { public static void serializeNullableString(ByteBuffer outputBuffer, String value) { if (value == null) { outputBuffer.putInt(0); } else { serializeString(outputBuffer, value, Charset.defaultCharset()); } }  }
Utils { public static void serializeNullableString(ByteBuffer outputBuffer, String value) { if (value == null) { outputBuffer.putInt(0); } else { serializeString(outputBuffer, value, Charset.defaultCharset()); } }  static String readShortString(DataInputStream input); static int getIntStringLength(String value); static String readIntString(DataInputStream input); static String readIntString(DataInputStream input, Charset charset); static ByteBuffer readIntBuffer(DataInputStream input); static ByteBuffer readShortBuffer(DataInputStream input); static ByteBufferInputStream getByteBufferInputStreamFromCrcInputStream(CrcInputStream crcStream, int dataSize); static ByteBuffer getByteBufferFromInputStream(InputStream stream, int dataSize); static ByteBuffer readByteBufferFromCrcInputStream(CrcInputStream crcStream, int dataSize); static ByteBuf readNettyByteBufFromCrcInputStream(CrcInputStream crcStream, int dataSize); static Exception extractExecutionExceptionCause(Exception e); static ByteBuf applyByteBufferFunctionToByteBuf(ByteBuf buf, ByteBufferFunction<T> fn); static Thread newThread(Runnable runnable, boolean daemon); static Thread newThread(String name, Runnable runnable, boolean daemon); static Thread daemonThread(Runnable runnable); static Thread daemonThread(String name, Runnable runnable); static ScheduledExecutorService newScheduler(int numThreads, String threadNamePrefix, boolean isDaemon); static ScheduledExecutorService newScheduler(int numThreads, boolean isDaemon); static FileChannel openChannel(File file, boolean mutable); static int readFileToByteBuffer(FileChannel fileChannel, long offset, ByteBuffer buffer); static T getObj(String className); static T getObj(String className, Object arg); static T getObj(String className, Object arg1, Object arg2); static T getObj(String className, Object arg1, Object arg2, Object arg3); static T getObj(String className, Object... args); static Stream<String> getStaticFieldValuesAsStrings(Class type); static int hashcode(Object[] items); static long crc32(byte[] bytes); static long crc32(byte[] bytes, int offset, int size); static Properties loadProps(String filename); static void serializeNullableString(ByteBuffer outputBuffer, String value); static void serializeNullableString(ByteBuf outputBuf, String value); static void serializeString(ByteBuffer outputBuffer, String value, Charset charset); static void serializeString(ByteBuf outputBuf, String value, Charset charset); static String deserializeString(ByteBuffer inputBuffer, Charset charset); static int getNullableStringLength(String value); static void writeStringToFile(String string, String path); static void writeJsonObjectToFile(JSONObject jsonObject, String path); static void writeJsonArrayToFile(JSONArray jsonArray, String path); static String readStringFromFile(String path); static boolean isLinux(); static void preAllocateFileIfNeeded(File file, long capacityBytes); static long getRandomLong(Random random, long n); static short getRandomShort(Random random); static long addSecondsToEpochTime(long epochTimeInMs, long deltaTimeInSeconds); static byte[] readBytesFromStream(InputStream stream, int size); static byte[] readBytesFromStream(InputStream stream, byte[] data, int offset, int size); static byte[] readBytesFromByteBuf(ByteBuf buffer, byte[] data, int offset, int size); static ArrayList<String> splitString(String data, String delimiter); static C splitString(String data, String delimiter,
      Supplier<C> collectionFactory); static List<List<T>> partitionList(List<T> inputList, int batchSize); static List<U> transformList(List<T> inputList, Function<T, U> transformer); static List<T> listView(IntSupplier currentSize, IntFunction<T> itemFetcher); static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength); static Throwable getRootCause(Throwable t); static long getTimeInMsToTheNearestSec(long timeInMs); static void shutDownExecutorService(ExecutorService executorService, long shutdownTimeout, TimeUnit timeUnit); static boolean isPossibleClientTermination(Throwable cause); static IOException convertToClientTerminationException(Throwable cause); static long getTtlInSecsFromExpiryMs(long expiresAtMs, long creationTimeMs); static int compareTimes(long time1, long time2); static void deleteFileOrDirectory(File file); static void setFilesPermission(List<File> files, Set<PosixFilePermission> permissions); static boolean isNullOrEmpty(String str); }
Utils { public static void serializeNullableString(ByteBuffer outputBuffer, String value) { if (value == null) { outputBuffer.putInt(0); } else { serializeString(outputBuffer, value, Charset.defaultCharset()); } }  static String readShortString(DataInputStream input); static int getIntStringLength(String value); static String readIntString(DataInputStream input); static String readIntString(DataInputStream input, Charset charset); static ByteBuffer readIntBuffer(DataInputStream input); static ByteBuffer readShortBuffer(DataInputStream input); static ByteBufferInputStream getByteBufferInputStreamFromCrcInputStream(CrcInputStream crcStream, int dataSize); static ByteBuffer getByteBufferFromInputStream(InputStream stream, int dataSize); static ByteBuffer readByteBufferFromCrcInputStream(CrcInputStream crcStream, int dataSize); static ByteBuf readNettyByteBufFromCrcInputStream(CrcInputStream crcStream, int dataSize); static Exception extractExecutionExceptionCause(Exception e); static ByteBuf applyByteBufferFunctionToByteBuf(ByteBuf buf, ByteBufferFunction<T> fn); static Thread newThread(Runnable runnable, boolean daemon); static Thread newThread(String name, Runnable runnable, boolean daemon); static Thread daemonThread(Runnable runnable); static Thread daemonThread(String name, Runnable runnable); static ScheduledExecutorService newScheduler(int numThreads, String threadNamePrefix, boolean isDaemon); static ScheduledExecutorService newScheduler(int numThreads, boolean isDaemon); static FileChannel openChannel(File file, boolean mutable); static int readFileToByteBuffer(FileChannel fileChannel, long offset, ByteBuffer buffer); static T getObj(String className); static T getObj(String className, Object arg); static T getObj(String className, Object arg1, Object arg2); static T getObj(String className, Object arg1, Object arg2, Object arg3); static T getObj(String className, Object... args); static Stream<String> getStaticFieldValuesAsStrings(Class type); static int hashcode(Object[] items); static long crc32(byte[] bytes); static long crc32(byte[] bytes, int offset, int size); static Properties loadProps(String filename); static void serializeNullableString(ByteBuffer outputBuffer, String value); static void serializeNullableString(ByteBuf outputBuf, String value); static void serializeString(ByteBuffer outputBuffer, String value, Charset charset); static void serializeString(ByteBuf outputBuf, String value, Charset charset); static String deserializeString(ByteBuffer inputBuffer, Charset charset); static int getNullableStringLength(String value); static void writeStringToFile(String string, String path); static void writeJsonObjectToFile(JSONObject jsonObject, String path); static void writeJsonArrayToFile(JSONArray jsonArray, String path); static String readStringFromFile(String path); static boolean isLinux(); static void preAllocateFileIfNeeded(File file, long capacityBytes); static long getRandomLong(Random random, long n); static short getRandomShort(Random random); static long addSecondsToEpochTime(long epochTimeInMs, long deltaTimeInSeconds); static byte[] readBytesFromStream(InputStream stream, int size); static byte[] readBytesFromStream(InputStream stream, byte[] data, int offset, int size); static byte[] readBytesFromByteBuf(ByteBuf buffer, byte[] data, int offset, int size); static ArrayList<String> splitString(String data, String delimiter); static C splitString(String data, String delimiter,
      Supplier<C> collectionFactory); static List<List<T>> partitionList(List<T> inputList, int batchSize); static List<U> transformList(List<T> inputList, Function<T, U> transformer); static List<T> listView(IntSupplier currentSize, IntFunction<T> itemFetcher); static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength); static Throwable getRootCause(Throwable t); static long getTimeInMsToTheNearestSec(long timeInMs); static void shutDownExecutorService(ExecutorService executorService, long shutdownTimeout, TimeUnit timeUnit); static boolean isPossibleClientTermination(Throwable cause); static IOException convertToClientTerminationException(Throwable cause); static long getTtlInSecsFromExpiryMs(long expiresAtMs, long creationTimeMs); static int compareTimes(long time1, long time2); static void deleteFileOrDirectory(File file); static void setFilesPermission(List<File> files, Set<PosixFilePermission> permissions); static boolean isNullOrEmpty(String str); static final long Infinite_Time; static final int MIN_PORT_NUM; static final int MAX_PORT_NUM; static final String ACCOUNT_CONTAINER_SEPARATOR; }