1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 23:50:49 +00:00

Try to avoid memory issues

This commit is contained in:
Arnaud Roques 2021-12-08 21:33:40 +01:00
parent d9552dfc34
commit 51ee3fb7c7
2 changed files with 20 additions and 13 deletions

View File

@ -16,6 +16,8 @@
package ext.plantuml.com.google.zxing.common;
import ext.plantuml.com.google.zxing.WriterException;
/**
* <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
*
@ -230,7 +232,10 @@ public final class BitArray {
}
private static int[] makeArray(int size) {
return new int[(size + 31) >> 5];
final int tmp = (size + 31) >> 5;
if (tmp>1000)
throw new IllegalArgumentException("Memory error");
return new int[tmp];
}
public String toString() {

View File

@ -56,18 +56,20 @@ public class FlashCodeUtilsZxing implements FlashCodeUtils {
if (USE_FLASH == false) {
return null;
}
try {
final QRCodeWriter writer = new QRCodeWriter();
final Hashtable hints = new Hashtable();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
final int multiple = 1;
final BitMatrix bit = writer.encode(s, BarcodeFormat.QR_CODE, multiple, hints);
return MatrixToImageWriter.toBufferedImage(bit, fore.getRGB() | 0xFF000000, back.getRGB() | 0xFF000000);
} catch (WriterException e) {
Log.debug("Cannot create qrcode " + e);
// e.printStackTrace();
return null;
synchronized (FlashCodeUtilsZxing.class) {
try {
final QRCodeWriter writer = new QRCodeWriter();
final Hashtable hints = new Hashtable();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
final int multiple = 1;
final BitMatrix bit = writer.encode(s, BarcodeFormat.QR_CODE, multiple, hints);
return MatrixToImageWriter.toBufferedImage(bit, fore.getRGB() | 0xFF000000, back.getRGB() | 0xFF000000);
} catch (WriterException e) {
Log.debug("Cannot create qrcode " + e);
// e.printStackTrace();
return null;
}
}
}