MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean diagnosticMXBean = ManagementFactory.newPlatformMXBeanProxy(mBeanServer,
"com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
heapDumpFile = File.createTempFile("heapdump", ".txt");
heapDumpFile.delete();
diagnosticMXBean.dumpHeap(heapDumpFile.getAbsolutePath(), false);
// copy the dump in the destination
in = new FileInputStream(heapDumpFile);
out = destination.add("heapdump.txt");
byte[] buffer = new byte[2048];
int l;