A good library to do URL Query String manipulation in Java [closed]

I need to do a few very simple URL manipulations in Java. Like get the value for a parameter in the query, or update it, ... I was expecting to find a simple utility class doing that in the commons-lang package, but no. I know it is a simple problem, but if there is something already written, why do it again ? Do you know of any ?

I would like to have at least the following capabilities :

String myUrl = "http://www.example.com/test.html?toto=1&titi=2";

// get the value of a parameter
String parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "1");

// update a parameter
String newUrl = UrlUtils.updateParameter(myUrl, "toto", 3);
parameterValue = UrlUtils.getParameterValue(myUrl, "toto");
Assert.equals(parameterValue, "3");

Ideally, it would take care of all encoding related issues, and work with java.net.Url as well as with Strings.

Thanks for your help !


Asked by: Julian839 | Posted: 23-01-2022






Answer 1

I think what you want is called a query string parser instead of an url manipulator and here's one: http://ostermiller.org/utils/CGIParser.java.html

Answered by: Roland594 | Posted: 24-02-2022



Answer 2

Apache's httpcomponents library has a URL decoder: http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html

Httpcomponents is the successor to commons http client.

Answered by: Kirsten405 | Posted: 24-02-2022



Answer 3

Indeed has released an efficient Java library for query string and number parsing:

http://engineering.indeed.com/blog/2014/02/efficient-query-string-parsing-util-urlparsing/

https://github.com/indeedeng/util/tree/master/urlparsing

(Disclaimer: I am an engineering director at Indeed.)

Answered by: Patrick806 | Posted: 24-02-2022



Similar questions

audio - Java Library for Sound Manipulation

I have a .pcm file with a sound that I would like to add different effects to. What I am looking for is a simple way (prefeably a library) that can help me with these effects. My top priority is to change the pitch of the audio. I would like a function that takes a byte array (or float), and changes the pitch of the audio in that array.


Low level JSON manipulation library for Java

I am looking for a 3rd party library which can manipulate entities stored as JSONs. This is intended to be used in the (cucumber) test framework to specifically tailor predefined JSON requests to a specific situation. For example let`s consider the following JSON { "user": { "name": "Bob", "age": 27, "email": "bob@something.com" } } Naturally the JSON above ...


bit manipulation - How can I turn an int into three bytes in Java?

I am trying to convert an int into three bytes representing that int (big endian). I'm sure it has something to do with bit-wise and and bit shifting. But I have no idea how to go about doing it. For example: int myInt; // some code byte b1, b2 , b3; // b1 is most significant, then b2 then b3. *Note, I am aware that an int is 4 byte...


bit manipulation - Bitwise AND, Bitwise Inclusive OR question, in Java

I've a few lines of code within a project, that I can't see the value of... buffer[i] = (currentByte & 0x7F) | (currentByte & 0x80); It reads the filebuffer from a file, stored as bytes, and then transfers then to buffer[i] as shown, but I can't understand what the overall purpose is, any ideas? Thanks


bit manipulation - In Java, when using bitshifts, why does 1 << 32 != 1 << 31 << 1?

int a = 1 &lt;&lt; 32; int b = 1 &lt;&lt; 31 &lt;&lt; 1; Why does a == 1? b is 0 as I expected.


bit manipulation - getting the bottom 16 bits of a Java int as a signed 16-bit value

Hmmm. Consider this program, whose goal is to figure out the best way to get the bottom 16 bits of an integer, as a signed integer. public class SignExtend16 { public static int get16Bits(int x) { return (x &amp; 0xffff) - ((x &amp; 0x8000) &lt;&lt; 1); } public static int get16Bits0(int x) { return (int)(short)(x); } public static void main(String[] args)...


bit manipulation - In Java, is it possible to clear a bit?

In Java, is it possible to clear a bit using bitwise operations?


java - TextBox Search string manipulation

This is sort of complicated for me to explain,let me try anyway. i want to know how can i manipulate the string i've collected from this(such type of ) textbox and use it for my pupose in webapp or dektop app. alt text http://img35.imageshack.us/img35/1495/searchr.jpg i mean for example, i've two situations. ...


Final variable manipulation in Java

Could anyone please tell me what is the meaning of the following line in context of Java: final variable can still be manipulated unless it's immutable As far as I know, by declaring any variable as final, you can't change it again, then what they mean with the word immutable in above line?


testing - How to test file system manipulation in Java

I'm writing a program that creates and edits directories and files in a file system. I want to write a test that does things like (1) check if the given directory exists and (2) create a directory within the existing directory. What is the best way to test functionality like this? Is there a way to fake a file system (e.g. in memory?) or would I have to just use a temporary outp...


bit manipulation - How do I compare two longs as unsigned in Java?

I'm storing bit patterns of unsigned 64-bit numbers in a long variable and want to calculate the distance between two of them on the unsigned range. Because Java interprets long as a two's complement signed integer, I can't just do a - b, as the following example shows: // on the unsigned range, these numbers would be adjacent long a = 0x7fffffffffffffffL; long b = 0x8...


bit manipulation - Finding Highest Order 1 in a Java Primitive

I need to find the highest order 1 in some longs, ints, and shorts in Java. For example, if I had a char that looked like 00110101, I need a method that will return 2 (index of highest order 1). Now, I know that you can do this using a for loop like: for(int i=0; i&lt;8; i++) if((x &amp; 1&lt;&lt;i) != 0) return i; return -1; but this is way slower than what I want...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top