com.tapstream.sdk.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tapstream-core Show documentation
Show all versions of tapstream-core Show documentation
This library contains the building blocks for a Tapstream Java SDK
package com.tapstream.sdk;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
public class Utils {
public static byte[] readFully(InputStream is) throws IOException {
if (is == null)
return null;
ByteArrayOutputStream responseBodyStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 8];
int bytesRead;
do {
bytesRead = is.read(buffer);
if (bytesRead != -1){
responseBodyStream.write(buffer, 0, bytesRead);
}
} while (bytesRead != -1);
return responseBodyStream.toByteArray();
}
public static void closeQuietly(Closeable obj){
try {
obj.close();
} catch (Exception e){
// Swallow any exceptions while closing
}
}
public static T getOrDefault(T value, T defaultValue){
if (value != null)
return value;
return defaultValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy