マウスでウィンドウのサイズを変更しようとすると、Java がフリーズして「CoreAnimation: 911 x 34488 image is too large for software renderer, ignoring 」エラーをスローするのはなぜですか?
これは、さらに原始的な UI を備えた原始的な RSA 暗号化/復号化クラスです。
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.List;
import java.security.*;
import javax.swing.*;
import java.awt.*;
public class rsa {
private final static SecureRandom random = new SecureRandom();
private static BigInteger privateKey;
private static BigInteger publicKey;
private static BigInteger modulus;
rsa(int N) {
BigInteger p = BigInteger.probablePrime(N / 2, random);
BigInteger q = BigInteger.probablePrime(N / 2, random);
BigInteger phi = (p.subtract(new BigInteger("1"))).multiply(q.subtract(new BigInteger("1")));
modulus = p.multiply(q);
publicKey = new BigInteger("65537");
privateKey = publicKey.modInverse(phi);
}
BigInteger encrypt(BigInteger message) {
return message.modPow(publicKey, modulus);
}
BigInteger decrypt(BigInteger encrypted) {
return encrypted.modPow(privateKey, modulus);
}
public static void main(String[] args) throws IOException {
int N = Integer.parseInt("2048");
rsa key = new rsa(N);
String tocode = "Even though I walk through the valley of the shadow of death, I will fear no evil, for you are with me; your rod and your staff, they comfort me.";
BigInteger intcode = new BigInteger(tocode.getBytes());
BigInteger encrypt = key.encrypt(intcode);
BigInteger decrypt = key.decrypt(encrypt);
Iterator<String> parcelIt = parcel(intcode, 10).iterator();
gui(tocode, intcode, encrypt, decrypt, N, parcelIt);
}
public static List<String> parcel(BigInteger inputInteger, int size) {
String inputString = inputInteger.toString();
List<String> parcelled = new ArrayList<String>();
parcelled.add(Arrays.toString(inputString.split("(?<=\\G.{" + size + "})")));
return parcelled;
}
public static void gui(String tocode, BigInteger intcode, BigInteger encrypt, BigInteger decrypt, int N, Iterator<String> parcelIt) {
JTextArea textarea = new JTextArea(0, 0);
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
Font font = new Font("Helvetica", Font.PLAIN, 9);
textarea.setFont(font);
textarea.setForeground(new Color(0x88, 0x88, 0xff));
textarea.setBackground(new Color(0x30, 0x30, 0x30));
textarea.append("Modulus:\n" + modulus + "\n\n");
textarea.append("Public key:\n" + publicKey + "\n\n");
textarea.append("Private key:\n" + privateKey + "\n\n");
textarea.append("Message in String:\n" + tocode + "\n\n");
textarea.append("Message in BigInteger:\n" + intcode + "\n\n");
textarea.append("Parcels: (for test only)\n");
while (parcelIt.hasNext()) {
String value = (String) parcelIt.next();
textarea.append(value + ", ");
}
textarea.append("\n\nEncrpyted message:\n" + encrypt + "\n\n\n\n");
textarea.append("Decrypted in BigInteger:\n" + decrypt + "\n\n");
textarea.append("Decrypted in String:\n" + new String(decrypt.toByteArray()) + "\n\n");
JFrame frame = new JFrame("RSA-" + N);
frame.add(textarea);
frame.setSize(900, 500);
Dimension windowSize = frame.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int windowX = Math.max(0, (screenSize.width - windowSize.width ) / 2);
int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2);
frame.setLocation(windowX, windowY);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
編集:
スタックトレース:
2013-03-29 00:59:42.707 java[38707:707] java.lang.OutOfMemoryError: can't create offscreen surface
at sun.java2d.opengl.OGLSurfaceData.initSurfaceNow(OGLSurfaceData.java:298)
at sun.java2d.opengl.OGLSurfaceData.access$000(OGLSurfaceData.java:98)
at sun.java2d.opengl.OGLSurfaceData$1.run(OGLSurfaceData.java:324)
at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:234)
2013-03-29 00:59:42.709 java[38707:707] (
0 CoreFoundation 0x00007fff8cdd7b06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8c81b3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8ce6bf49 -[NSException raise] + 9
3 JavaNativeFoundation 0x0000000124065539 JNFCallVoidMethod + 209
4 liblwawt.dylib 0x0000000124ef4f77 -[AWTWindow _deliverMoveResizeEvent] + 310
5 CoreFoundation 0x00007fff8cd89eda _CFXNotificationPost + 2554
6 Foundation 0x00007fff91d48e26 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7 AppKit 0x00007fff8eb0a4ce -[NSWindow _setFrameCommon:display:stashSize:] + 2322
8 AppKit 0x00007fff8f253a69 -[NSWindow(NSWindowResizing) _resizeWithEvent:] + 1587
9 AppKit 0x00007fff8f059de9 -[NSTitledFrame mouseDown:] + 189
10 AppKit 0x00007fff8f0577fe -[NSThemeFrame mouseDown:] + 281
11 AppKit 0x00007fff8ebc053e -[NSWindow sendEvent:] + 6853
12 liblwawt.dylib 0x0000000124ef2e33 -[AWTWindow_Normal sendEvent:] + 86
13 AppKit 0x00007fff8ebbc674 -[NSApplication sendEvent:] + 5761
14 libosxapp.dylib 0x000000012481cad1 -[NSApplicationAWT sendEvent:] + 179
15 AppKit 0x00007fff8ead224a -[NSApplication run] + 636
16 libosxapp.dylib 0x000000012481c9b9 +[NSApplicationAWT runAWTLoopWithApp:] + 156
17 liblwawt.dylib 0x0000000124ee4a5a -[AWTStarter starter:] + 1591
18 Foundation 0x00007fff91d92d3a __NSThreadPerformPerform + 225
19 CoreFoundation 0x00007fff8cd56b31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00007fff8cd56455 __CFRunLoopDoSources0 + 245
21 CoreFoundation 0x00007fff8cd797f5 __CFRunLoopRun + 789
22 CoreFoundation 0x00007fff8cd790e2 CFRunLoopRunSpecific + 290
23 java 0x000000010b5264bc CreateExecutionEnvironment + 871
24 java 0x000000010b520cac JLI_Launch + 1952
25 java 0x000000010b526819 main + 101
26 java 0x000000010b520504 start + 52
27 ??? 0x0000000000000005 0x0 + 5
)