Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve encoder parameter configuration #196

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public class Example {
FileInputStream inFile = new FileInputStream(filePath);
FileOutputStream outFile = new FileOutputStream(filePath + ".br");

Encoder.Parameters params = new Encoder.Parameters().setQuality(4);
Encoder.Parameters params = new Encoder.Parameters.create(4);

BrotliOutputStream brotliOutputStream = new BrotliOutputStream(outFile, params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,34 @@ public static final class Parameters {
public Parameters() {
}

private Parameters(Parameters other) {
this.quality = other.quality;
this.lgwin = other.lgwin;
this.mode = other.mode;
/**
* @param quality compression quality, or -1 for default
* @return this instance
*/
public static Parameters create(int quality) {
return create(quality, -1);
}

/**
* @param quality compression quality, or -1 for default
* @param lgwin log2(LZ window size), or -1 for default
* @return this instance
*/
public static Parameters create(int quality, int lgwin) {
return create(quality, lgwin, null);
}

/**
* @param quality compression quality, or -1 for default
* @param lgwin log2(LZ window size), or -1 for default
* @param mode compression mode, or {@code null} for default
* @return this instance
*/
public static Parameters create(int quality, int lgwin, Mode mode) {
return new Parameters()
.setQuality(quality)
.setWindow(lgwin)
.setMode(mode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void compress() throws IOException {

@Test
void compressWithQuality() throws IOException {
assertArrayEquals(compressedData, Encoder.compress("Meow".getBytes(), new Encoder.Parameters().setQuality(6)));
assertArrayEquals(compressedData, Encoder.compress("Meow".getBytes(), Encoder.Parameters.create(6)));
}

@Test
Expand Down
Loading