With regex in Java, I want to write a regex that will match if and only if the pattern is not preceded by certain characters. For example: I want to match if bar is not preceded by foo. So the output would be: Answer You want to use negative lookbehind like this: Where (?<!x) means “only if it doesn&…
Tag: java
How to make a copy of a file in android?
In my app I want to save a copy of a certain file with a different name (which I get from user) Do I really need to open the contents of the file and write it to another file? What is the best way …
Validating a Signature of a SOAP Message
Everybody, Hello! This is my request message: I try to validate the <ds:DigestValue>RJhc1ZVjXdUQEIwLTH356p7H0QY=</ds:DigestValue> which is related to the body tag. There are tags like ds:CanonicalizationMethod and ds:Transformswhich are really confusing for me. My question is how to validate the b…
How can I call servlet from jsp without using form
This could be a repeat question, I apologize. I have a jsp page in which I have some buttons. Each button has its own servlet to call. I want to know if there is any way I can call these servlets without using form because the user may choose any of the 3 functionalities given. I also need to pass
Difference between namespace in C# and package in Java
What is the difference (in terms of use) between namespaces in C# and packages in Java? Answer From: http://www.javacamp.org/javavscsharp/namespace.html Java Packages are used to organize files or public types to avoid type conflicts. Package constructs can be mapped to a file system. may be replaced: There i…
Parsing RTSP stream for live radio
I want to be able to parse the rtsp stream in order to extract data about the radio station, current playing song name, duration etc. I have to do it manually – no libraries. Preferred language is Java but I could work with something else too. Answer Welcome to the world of RFC 2326: Real Time Streaming…
Using mockito to test methods which throw uncaught custom exceptions
How do I write a Mockito-based JUnit method to test this method adduser()? I tried writing one, but it’s failing with an error message saying exception is not handled. The error is displayed for: Assume addUser() method in business class never catches any exception and rethrowing is not done. TEST CASE …
Hibernate / JPA many to many relationship through a join table and a composite key, Unique Constraint issue
So I asked this question yesterday, but the goal posts have changed and the question is different: Hibernate / JPA Collection of Elements with Many to Many relationship? I want to know if it’s possible to create entities that will model my required relationship so that Hibernate will create my schema wh…
HDF5 in Java: What are the difference between the availabe APIs?
I’ve just discovered the HDF5 format and I’m considering using it to store 3D data spread over a cluster of Java application servers. I have found out that there are several implementations available for Java, and would like to know the differences between them: Java HD5 Interface (JHI5) The Java …
how to convert PrintWriter to String or write to a File?
I am generating dynamic page using JSP, I want to save this dynamically generated complete page in file as archive. In JSP, everything is written to PrintWriter out = response.getWriter(); At the end of page, before sending response to client I want to save this page, either in file or in buffer as string for…