-
Notifications
You must be signed in to change notification settings - Fork 472
suggest prettier plugins as appropriate #1511
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
Merged
nedtwigg
merged 8 commits into
diffplug:main
from
simschla:1416-suggest-prettier-plugins-as-appropriate
Jan 24, 2023
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bba246d
1416: use process runner to catch output
simschla 1c285ec
1416: suggest prettier plugins
simschla 32eee78
1416: limit output fetched by npm process
simschla 8b56d5d
1416: document changes
simschla 2c54ee9
1416: Integrate PR Feedback
simschla c0cd99d
1416: spotbugs adaptions
simschla 4aa3b7e
Run spotbugs in all configurations because it's not that slow (17 sec…
nedtwigg c849de8
Revert previous commit b/c spotbugs gives errant warnings on Java 8.
nedtwigg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright 2023 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStream { | ||
|
||
private final int limit; | ||
|
||
private int zeroIndexPointer = 0; | ||
|
||
private boolean isOverLimit = false; | ||
|
||
public LimitedOverwritingByteArrayOutputStream(int limit) { | ||
this(limit, 32); | ||
} | ||
|
||
public LimitedOverwritingByteArrayOutputStream(int limit, int initialCapacity) { | ||
super(initialCapacity); | ||
if (limit < initialCapacity) { | ||
throw new IllegalArgumentException("Limit must be greater than initial capacity"); | ||
} | ||
if (limit < 0) { | ||
throw new IllegalArgumentException("Limit must be greater than 0"); | ||
simschla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (limit % 2 != 0) { | ||
throw new IllegalArgumentException("Limit must be even"); // to fit 16 bit unicode chars | ||
} | ||
this.limit = limit; | ||
} | ||
|
||
// ---- writing | ||
@Override | ||
public synchronized void write(int b) { | ||
if (count < limit) { | ||
super.write(b); | ||
return; | ||
} | ||
isOverLimit = true; | ||
buf[zeroIndexPointer] = (byte) b; | ||
zeroIndexPointer = (zeroIndexPointer + 1) % limit; | ||
} | ||
|
||
@Override | ||
public synchronized void write(byte[] b, int off, int len) { | ||
int remaining = limit - count; | ||
if (remaining >= len) { | ||
super.write(b, off, len); | ||
return; | ||
} | ||
if (remaining > 0) { | ||
// write what we can "normally" | ||
super.write(b, off, remaining); | ||
// rest delegated | ||
write(b, off + remaining, len - remaining); | ||
return; | ||
} | ||
// we are over the limit | ||
isOverLimit = true; | ||
// write till limit is reached | ||
int writeTillLimit = Math.min(len, limit - zeroIndexPointer); | ||
System.arraycopy(b, off, buf, zeroIndexPointer, writeTillLimit); | ||
zeroIndexPointer = (zeroIndexPointer + writeTillLimit) % limit; | ||
if (writeTillLimit < len) { | ||
// write rest | ||
write(b, off + writeTillLimit, len - writeTillLimit); | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void reset() { | ||
super.reset(); | ||
zeroIndexPointer = 0; | ||
isOverLimit = false; | ||
} | ||
|
||
// ---- output | ||
@Override | ||
public synchronized void writeTo(OutputStream out) throws IOException { | ||
if (!isOverLimit) { | ||
super.writeTo(out); | ||
return; | ||
} | ||
out.write(buf, zeroIndexPointer, limit - zeroIndexPointer); | ||
out.write(buf, 0, zeroIndexPointer); | ||
} | ||
|
||
@Override | ||
public synchronized byte[] toByteArray() { | ||
if (!isOverLimit) { | ||
return super.toByteArray(); | ||
} | ||
byte[] result = new byte[limit]; | ||
System.arraycopy(buf, zeroIndexPointer, result, 0, limit - zeroIndexPointer); | ||
System.arraycopy(buf, 0, result, limit - zeroIndexPointer, zeroIndexPointer); | ||
return result; | ||
} | ||
|
||
@Override | ||
public synchronized String toString() { | ||
if (!isOverLimit) { | ||
return super.toString(); | ||
} | ||
return new String(buf, zeroIndexPointer, limit - zeroIndexPointer) + new String(buf, 0, zeroIndexPointer); | ||
} | ||
|
||
@Override | ||
public synchronized String toString(String charsetName) throws UnsupportedEncodingException { | ||
if (!isOverLimit) { | ||
return super.toString(charsetName); | ||
} | ||
return new String(buf, zeroIndexPointer, limit - zeroIndexPointer, charsetName) + new String(buf, 0, zeroIndexPointer, charsetName); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.