import com.sun.btrace.AnyType; import com.sun.btrace.annotations.*; import static com.sun.btrace.BTraceUtils.*; @BTrace public class Trace { @OnMethod(clazz = "+java.lang.ClassLoader", method = "defineClass") public static void traceClassLoaderLeak(@ProbeClassName String clazz, @ProbeMethodName String method, @TargetInstance Object instance) { println("\n==== java.lang.ClassLoader#defineClass ===="); jstack(); } }
Wednesday 12 November 2014
BTrace trace ClassLoader Leaking
If you want to trace the common ClassLoader leaking, you just probe where to invoke "ClassLoader#defineClass". The BTrace script as follow:
Thursday 8 May 2014
Java client read content from URL with SSL
- Java client
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class PDFTester { private static final int FILE_BUFFER_SIZE = 2048; public static final String CONTENT_TYPE_PDF = "application/pdf"; public static byte[] readPDFFromURL(URL url) throws IOException { System.setProperty("javax.net.ssl.trustStore", "C:/temp/myCA.jks"); System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection(); httpsURLConnection.setHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }); httpsURLConnection.connect(); byte[] buffer = new byte[FILE_BUFFER_SIZE]; int lengthOfByteToBeWrite; try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); InputStream inputStream = httpsURLConnection.getInputStream()) { while ((lengthOfByteToBeWrite = inputStream.read(buffer)) != -1) { byteArrayOutputStream.write(buffer, 0, lengthOfByteToBeWrite); } byteArrayOutputStream.flush(); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw e; } } public static void main(String[] args) throws IOException, URISyntaxException { URL url = new URL("https://www.sample.com/pdf"); byte[] bytes = readPDFFromURL(url); Path path = Paths.get("c:/temp/test.pdf"); Files.write(path, bytes); } }
Implementing SSL / TLS using Java
Sunday 6 April 2014
Hide unnecessary Horizontal Scrollbar on jqgrid
use this css to remove it.
Thursday 6 March 2014
Share value between main report, multi sub reports
How to shared value
between multi crystal report sub report?
1.
Create two sub reports
2.
Define Formula Field (defineGlobalPersonName)
in subReport1
3.
Tricky: This formula field (defineGlobalPersonName) must use in somewhere in sub report (subReport1) where inject value into the shared variable.
Otherwise, other sub report where reference the shared value (personName) can’t get
the value when printing records.
4.
Used shared variable in other sub report (subReport2)
(a)
Declare another “formula field (retreiveBackPersonName)” to retrieve value from above shared
variable (personName)
(b)
Use this formula field (retreiveBackPersonName)
in your sub report (subReport2)
5.
Preview final report
6.
If you want shared value to main report
as well. You just only declare one “formula
field (sharedValue)” in main report. Then you can use it
Thursday 6 February 2014
use external icons in Bootstrap
- 1. Define you own css
.icon-pdf-file { background-image: url(../img/document-pdf.png); background-position: center center; height: 16px; width: 16px; }
Subscribe to:
Posts (Atom)