Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,12 @@
</Match>

<!-- Retrieves and updates crc value in update() -->
<Match>
<Or>
<Class name="software.amazon.awssdk.checksums.internal.SdkCrc32CChecksum"/>
<Class name="software.amazon.awssdk.checksums.internal.SdkCrc32Checksum"/>
<Class name="software.amazon.awssdk.core.internal.checksums.factory.SdkCrc32C"/>
<Class name="software.amazon.awssdk.core.internal.checksums.factory.SdkCrc32"/>
</Or>
<Bug pattern="SA_FIELD_SELF_ASSIGNMENT"/>
<Match>
<Or>
<Class name="software.amazon.awssdk.checksums.internal.SdkCrc32CChecksum"/>
<Class name="software.amazon.awssdk.checksums.internal.SdkCrc32Checksum"/>
</Or>
<Bug pattern="SA_FIELD_SELF_ASSIGNMENT"/>
</Match>

<!-- Suppress existing blocking call. -->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,23 @@

package software.amazon.awssdk.core.checksums;

import static software.amazon.awssdk.core.internal.util.HttpChecksumUtils.longToByte;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.zip.Checksum;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.internal.checksums.factory.CrtBasedChecksumProvider;
import software.amazon.awssdk.core.internal.checksums.factory.SdkCrc32C;
import software.amazon.awssdk.annotations.SdkProtectedApi;
import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm;
import software.amazon.awssdk.core.internal.checksums.LegacyDelegatingChecksum;

/**
* Implementation of {@link SdkChecksum} to calculate an CRC32C checksum.
* <p>
* Implementor notes: this should've been an internal API, but we can't change it now since it's not within the internal
* subpackage.
*
* @deprecated this class is deprecated and subject to removal.
*/
@Deprecated
@SdkInternalApi
public class Crc32CChecksum implements SdkChecksum {

private Checksum crc32c;
private Checksum lastMarkedCrc32C;
private final boolean isCrtBasedChecksum;
@SdkProtectedApi
public class Crc32CChecksum extends LegacyDelegatingChecksum {

/**
* Creates CRT Based Crc32C checksum if Crt classpath for Crc32c is loaded, else create Sdk Implemented Crc32c
*/
public Crc32CChecksum() {
crc32c = CrtBasedChecksumProvider.createCrc32C();
isCrtBasedChecksum = crc32c != null;
if (!isCrtBasedChecksum) {
crc32c = SdkCrc32C.create();
}
}

@Override
public byte[] getChecksumBytes() {
return Arrays.copyOfRange(longToByte(crc32c.getValue()), 4, 8);
}


@Override
public void mark(int readLimit) {
this.lastMarkedCrc32C = cloneChecksum(crc32c);
}

@Override
public void update(int b) {
crc32c.update(b);
}

@Override
public void update(byte[] b, int off, int len) {
crc32c.update(b, off, len);
}

@Override
public long getValue() {
return crc32c.getValue();
}

@Override
public void reset() {
if (lastMarkedCrc32C == null) {
crc32c.reset();
} else {
crc32c = cloneChecksum(lastMarkedCrc32C);
}
}


private Checksum cloneChecksum(Checksum checksum) {
if (isCrtBasedChecksum) {
try {
Method method = checksum.getClass().getDeclaredMethod("clone");
return (Checksum) method.invoke(checksum);
} catch (ReflectiveOperationException e) {
throw new IllegalStateException("Could not clone checksum class " + checksum.getClass(), e);
}
} else {
return (Checksum) ((SdkCrc32C) checksum).clone();

}
super(DefaultChecksumAlgorithm.CRC32C);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,24 @@

package software.amazon.awssdk.core.checksums;

import static software.amazon.awssdk.core.internal.util.HttpChecksumUtils.longToByte;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.zip.Checksum;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.internal.checksums.factory.CrtBasedChecksumProvider;
import software.amazon.awssdk.core.internal.checksums.factory.SdkCrc32;
import software.amazon.awssdk.annotations.SdkProtectedApi;
import software.amazon.awssdk.checksums.DefaultChecksumAlgorithm;
import software.amazon.awssdk.core.internal.checksums.LegacyDelegatingChecksum;

/**
* Implementation of {@link SdkChecksum} to calculate an CRC32 checksum.
*
* <p>
* Implementor notes: this should've been an internal API, but we can't change it now since it's not within the internal
* subpackage.
*
* @deprecated this class is deprecated and subject to removal.
*/
@Deprecated
@SdkInternalApi
public class Crc32Checksum implements SdkChecksum {
@SdkProtectedApi
public class Crc32Checksum extends LegacyDelegatingChecksum {

private Checksum crc32;
private Checksum lastMarkedCrc32;
private final boolean isCrtBasedChecksum;

/**
* Creates CRT Based Crc32 checksum if Crt classpath for Crc32 is loaded, else create Sdk Implemented Crc32.
*/
public Crc32Checksum() {
crc32 = CrtBasedChecksumProvider.createCrc32();
isCrtBasedChecksum = crc32 != null;
if (!isCrtBasedChecksum) {
crc32 = SdkCrc32.create();
}
}

@Override
public byte[] getChecksumBytes() {
return Arrays.copyOfRange(longToByte(crc32.getValue()), 4, 8);
}

@Override
public void mark(int readLimit) {
this.lastMarkedCrc32 = cloneChecksum(crc32);
}

@Override
public void update(int b) {
crc32.update(b);
}

@Override
public void update(byte[] b, int off, int len) {
crc32.update(b, off, len);
}

@Override
public long getValue() {
return crc32.getValue();
}

@Override
public void reset() {
if ((lastMarkedCrc32 == null)) {
crc32.reset();
} else {
crc32 = cloneChecksum(lastMarkedCrc32);
}
}

private Checksum cloneChecksum(Checksum checksum) {
if (isCrtBasedChecksum) {
try {
Method method = checksum.getClass().getDeclaredMethod("clone");
return (Checksum) method.invoke(checksum);
} catch (ReflectiveOperationException e) {
throw new IllegalStateException("Could not clone checksum class " + checksum.getClass(), e);
}
} else {
return (Checksum) ((SdkCrc32) checksum).clone();
}
super(DefaultChecksumAlgorithm.CRC32);
}
}
Loading
Loading