package dyvil.runtime;

import dyvil.annotation.internal.NonNull;
import dyvil.io.Files;

import java.io.File;

public class BytecodeDump
{
	private static final String dumpProperty = System.getProperty("dyvil.bytecode.dump");
	private static final File dumpDirectory = dumpProperty == null ? null : new File(dumpProperty);

	@SuppressWarnings("ConstantConditions")
	public static void dump(byte @NonNull [] bytes, @NonNull String className)
	{
		if (dumpDirectory != null)
		{
			File dumpFile = new File(dumpDirectory, className.replace('/', File.separatorChar).concat(".class"));
			Files.tryWriteData(dumpFile, bytes);
		}
	}
}

@@ -63,28 +63,28 @@
 ll;%0A
+%0A
 import 
-dyvil
+java
 .io.File
 s;%0A%0A
@@ -83,11 +83,9 @@
 File
-s;%0A
+;
 %0Aimp
@@ -100,16 +100,56 @@
 .io.File
+OutputStream;%0Aimport java.io.IOException
 ;%0A%0Apubli
@@ -213,16 +213,17 @@
 roperty 
+ 
 = System
@@ -282,24 +282,26 @@
  final File 
+  
 dumpDirector
@@ -364,47 +364,129 @@
 ;%0A%0A%09
-@SuppressWarnings(%22ConstantConditions%22)
+static%0A%09%7B%0A%09%09if (dumpDirectory != null)%0A%09%09%7B%0A%09%09%09//noinspection ResultOfMethodCallIgnored%0A%09%09%09dumpDirectory.mkdirs();%0A%09%09%7D%0A%09%7D%0A
 %0A%09pu
@@ -706,44 +706,138 @@
 %0A%09%09%09
-Files.tryWriteData(dumpFile, bytes);
+try (FileOutputStream os = new FileOutputStream(dumpFile))%0A%09%09%09%7B%0A%09%09%09%09os.write(bytes);%0A%09%09%09%7D%0A%09%09%09catch (IOException ignored)%0A%09%09%09%7B%0A%09%09%09%7D
 %0A%09%09%7D

Fix infinite invokedynamic recursion in BytecodeDump