Programming and more

Entries Tagged ‘java’

Simple way to get md5 from string in java

You will see a lot of crazy shit when searching for this. I you want something simple, get this function to get md5 from string in java: static String md5(String text) { try { MessageDigest m=MessageDigest.getInstance("MD5"); m.update(text.getBytes(),0,text.length()); return new BigInteger(1,m.digest()).toString(16); } catch (Exception e) { e.printStackTrace(); } return ""; } static String md5(String text) { […]

How to convert byte to String in Java

Java always has something easy implemeted 🙂 So this time, Java String has 2 constructors that take a byte[] array. So: byte[] buf = new byte[1024]; //or whatever […] Fill all the byte array or part of it […] String str = new String(buf);   OR   String str = new String(buf,start,limit); //To create a […]

How to unzip a zip file with java

How to unzip a zip file with java I was writing a script in java, to download the some files from a webserver, then open them and read then, and insert some files into the database. What i noticed was that. when i downloaded the files with my browser, everything was ok, but when i […]

How to remove duplicates in a Vector in java

Remove Dublicate entries in Java Vector I was writing a small java program, that copied some ids from a website. Then the program had to process each one of those ids. I used Vector to store these, then i realized that there are a lot of duplicates. To late to change to something else, Like […]

OpenVZ VPS and Java Memory Error and how to fix it.

There is a “bug” or more correctly an error when someone is trying to run a simple Java Program inside a OpenVZ (HyperVM, Virtuozzo) VPS. If you are in a harry and just want the answer, scroll down to the post and see it. It the story goes like this:   The problem: At first […]