Skip to content

Commit

Permalink
~ sonar: fixed some 'bugs'
Browse files Browse the repository at this point in the history
  • Loading branch information
kasisoft committed Aug 20, 2024
1 parent fa62fa3 commit f9a39ab
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public int getMinSize() {
@Override
public boolean test(byte[] data) {
if (getMinSize() <= data.length) {
return (((data[1] << 8) | data[0]) & 0x0000FFFF) == GZIPInputStream.GZIP_MAGIC;
return (((data[1] << 8) | (data[0] & 0xFF)) & 0x0000FFFF) == GZIPInputStream.GZIP_MAGIC;
}
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/kasisoft/libs/common/io/IoFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ public static Optional<Path> findNewTempFile(String prefix, String suffix) {
public static void skip(InputStream input, @Min(0) long size) {
if (size > 0) {
try {
input.skip(size);
long remaining = size;
long skipped = input.skip(remaining);
while (remaining > 0) {
remaining -= skipped;
skipped = input.skip(remaining);
}
} catch (Exception ex) {
throw KclException.wrap(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class FileIoSupport implements IoSupport<File> {

private static final long MB_16 = 16 * 1024 * 1024;
private static final long MB_16 = 16L * 1024 * 1024;

@Override
public InputStream newInputStreamImpl(File source) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class PathIoSupport implements IoSupport<Path> {

private static final long MB_16 = 16 * 1024 * 1024;
private static final long MB_16 = 16L * 1024 * 1024;

@Override
public InputStream newInputStreamImpl(Path source) throws Exception {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/kasisoft/libs/common/utils/Encryptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,22 @@ private String setupSecret(String secret) {
return result;
}

@NotNull
private KeyGenerator keyGenerator() {
try {
return KeyGenerator.getInstance(algorithm);
} catch (NoSuchAlgorithmException ex) {
// won't happen as it had been tested before
// won't happen as it had been tested before (see #verify)
return null;
}
}

@NotNull
private Cipher cipher() {
try {
return Cipher.getInstance(cipher);
} catch (NoSuchAlgorithmException | NoSuchPaddingException ex) {
// won't happen as it had been tested before
// won't happen as it had been tested before (see #verify)
return null;
}
}
Expand Down

0 comments on commit f9a39ab

Please sign in to comment.