Skip to content

Commit c465a9a

Browse files
committed
Remove PerMessageDeflateExtension#getCompressionRatio()
This new API was intended to be called by library users, but could never have worked, as it would need to be called on the class instance which is actually processing frames, but that instance is created internally in the library using copyInstance() and thus inaccessible to the library users. Remove the API and the stats kept for it.
1 parent 238fc82 commit c465a9a

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ public class PerMessageDeflateExtension extends CompressionExtension {
9696
private boolean isDecompressorResetAllowed;
9797
private boolean isCompressing;
9898
private boolean isDecompressing;
99-
private long compressedBytes;
100-
private long decompressedBytes;
10199

102100
public PerMessageDeflateExtension() {
103101
this(DEFAULT_COMPRESSION);
@@ -128,8 +126,6 @@ public PerMessageDeflateExtension(int compressionLevel, int maxFragmentSize) {
128126
isDecompressorResetAllowed = false;
129127
isCompressing = false;
130128
isDecompressing = false;
131-
compressedBytes = 0;
132-
decompressedBytes = 0;
133129
}
134130

135131
public int getCompressionLevel() {
@@ -164,21 +160,6 @@ public void setServerNoContextTakeover(boolean serverNoContextTakeover) {
164160
this.serverNoContextTakeover = serverNoContextTakeover;
165161
}
166162

167-
/**
168-
* Returns the overall compression ratio of all incoming and outgoing payloads which were
169-
* compressed.
170-
*
171-
* <p>Values below 1 mean the compression is effective, the lower, the better. If you get values
172-
* above 1, look into increasing the compression level or the threshold. If that does not help,
173-
* consider not using this extension.
174-
*
175-
* @return the overall compression ratio of all incoming and outgoing payloads
176-
*/
177-
public double getCompressionRatio() {
178-
double decompressed = decompressedBytes;
179-
return decompressed > 0 ? compressedBytes / decompressed : 1;
180-
}
181-
182163
@Override
183164
public void isFrameValid(Framedata inputFrame) throws InvalidDataException {
184165
// RFC 7692: RSV1 may only be set for the first fragment of a message
@@ -213,9 +194,7 @@ public void decodeFrame(Framedata inputFrame) throws InvalidDataException {
213194
// decompress the frame payload
214195
DataFrame dataFrame = (DataFrame) inputFrame;
215196
ByteBuffer payload = dataFrame.getPayloadData();
216-
compressedBytes += payload.remaining();
217197
byte[] decompressed = decompress(payload, dataFrame.isFin());
218-
decompressedBytes += decompressed.length;
219198
dataFrame.setPayload(ByteBuffer.wrap(decompressed));
220199

221200
// payload is no longer compressed, clear the RFC 7692 compression marker RSV1
@@ -298,9 +277,7 @@ public void encodeFrame(Framedata inputFrame) {
298277
// compress the frame payload
299278
DataFrame dataFrame = (DataFrame) inputFrame;
300279
ByteBuffer payload = dataFrame.getPayloadData();
301-
decompressedBytes += payload.remaining();
302280
byte[] compressed = compress(payload, dataFrame.isFin());
303-
compressedBytes += compressed.length;
304281
dataFrame.setPayload(ByteBuffer.wrap(compressed));
305282

306283
// payload is compressed now, set the RFC 7692 compression marker RSV1
@@ -568,10 +545,9 @@ public IExtension copyInstance() {
568545

569546
@Override
570547
public void reset() {
548+
super.reset();
571549
isCompressing = false;
572550
isDecompressing = false;
573-
compressedBytes = 0;
574-
decompressedBytes = 0;
575551
}
576552

577553
@Override

0 commit comments

Comments
 (0)