Issue
I need to extract each unique time stamp from following using Java.
2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - Exception caught in doInBackground runnable, ThreadId = 56, Exception = ServiceCommunicationException: javax.ejb.EJBException: java.nio.channels.ClosedChannelException common.service.ServiceCommunicationException: javax.ejb.EJBException: java.nio.channels.ClosedChannelException at .ejb.AbstractRequestDecorationProxy.invoke(AbstractRequestDecorationProxy.java:116)
2022.01.07 13:36:01 > [CDEThreadPool-thread-10] - javax.ejb.EJBException: java.nio.channels.ClosedChannelException at framework.CDEThreadPool$WrappedRunnable.run(CDEThreadPool.java:143) java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) Caused by: java.nio.channels.ClosedChannelException: null ... 38 common frames omitted 2022.01.07 13:36:01 > [CDEThreadPool-thread-7] - javax.ejb.EJBException: java.nio.channels.ClosedChannelException client.framework.ExtendedNonSOCBoundSwingWorker$2.run(ExtendedNonSOCBoundSwingWorker.java:276) at client.framework.CDEThreadPool$WrappedRunnable.run(CDEThreadPool.java:143) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - : 5.12.3-SNAPSHOT 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - JRE version: 1.8.0_292 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - OS version: Windows 10, 10.0 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - Server: 127.0.0.1:4447 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - ---------------------- 2022.01.07 13:28:49 > [CDEThreadPool-thread-10] - javax.ejb.EJBException: java.nio.channels.ClosedChannelException sdk.common.service.ServiceCommunicationException: javax.ejb.EJBException: java.nio.channels.ClosedChannelException .ejb.AbstractRequestDecorationProxy.invoke(AbstractRequestDecorationProxy.java:116)
the output should be like
2022.01.07 13:28:49 2022.01.07 13:36:01 2022.01.07 13:28:49
Solution
You may do a regex search on the pattern \d{4}\.\d{2}\.\d{2} \d{2}:\d{2}:\d{2}
:
String input = "YOUR LOG FILE HERE...";
String pattern = "\\d{4}\\.\\d{2}\\.\\d{2} \\d{2}:\\d{2}:\\d{2}";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(input);
List<String> timestamps = new ArrayList<>();
while (m.find()) {
timestamps.add(m.group());
}
Answered By - Tim Biegeleisen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.