com.palominolabs.http.url.StringBuilderPercentEncoderOutputHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of url-builder Show documentation
Show all versions of url-builder Show documentation
Create properly-encoded URLs with a builder-style API.
The newest version!
package com.palominolabs.http.url;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
/**
* A PercentEncoderHandler implementation that accumulates chars in a buffer.
*/
@NotThreadSafe
public final class StringBuilderPercentEncoderOutputHandler implements PercentEncoderOutputHandler {
private final StringBuilder stringBuilder;
/**
* Create a new handler with a default size StringBuilder.
*/
public StringBuilderPercentEncoderOutputHandler() {
stringBuilder = new StringBuilder();
}
/**
* @return A string containing the chars accumulated since the last call to reset()
*/
@Nonnull
public String getContents() {
return stringBuilder.toString();
}
/**
* Clear the buffer.
*/
public void reset() {
stringBuilder.setLength(0);
}
/**
* Ensure the internal buffer has enough capacity for the specified length of input.
*
* @param length length to ensure capacity for
*/
public void ensureCapacity(int length) {
stringBuilder.ensureCapacity(length);
}
@Override
public void onOutputChar(char c) {
stringBuilder.append(c);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy