io.virtdata.libbasics.shared.from_long.to_string.ToBase64String Maven / Gradle / Ivy
package io.virtdata.libbasics.shared.from_long.to_string;
import io.virtdata.annotations.Categories;
import io.virtdata.annotations.Category;
import io.virtdata.annotations.Example;
import io.virtdata.annotations.ThreadSafeMapper;
import java.nio.ByteBuffer;
import java.util.Base64;
import java.util.function.LongFunction;
@Categories(Category.conversion)
@ThreadSafeMapper
public class ToBase64String implements LongFunction {
private final static ThreadLocal tl_state = ThreadLocal.withInitial(TLState::new);
@Example({"ToBase64String()","Convert the bytes of a long input into a base64 String"})
public ToBase64String() {
}
@Override
public String apply(long value) {
TLState state = tl_state.get();
state.bytes.putLong(0,value);
return state.encoder.encodeToString(state.bytes.array());
}
private static class TLState {
public Base64.Encoder encoder = Base64.getEncoder();
public ByteBuffer bytes = ByteBuffer.allocate(Long.BYTES);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy