Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 1392a18693
...
compare: 04c18bf9dc
  • 9 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 144 additions and 0 deletions.
  1. +137 −0 java/AnuRandom.java
  2. +7 −0 java/example.java
View
137 java/AnuRandom.java
@@ -0,0 +1,137 @@
+import java.io.*;
+import java.net.*;
+
+/**
+@author Kristian Lundkvist <kristian.lundkvist@gmail.com>
+*/
+
+/**
+A class for downloading and parsing a 1024 bytes of random data from http://150.203.48.55/RawChar.php
+*/
+public class AnuRandom{
+
+ /**
+ DataInputStream using for reading from the website.
+ */
+ private DataInputStream in;
+
+ /**
+ Variable temporary storing the webpage.
+ */
+ private String page;
+
+ /**
+ Stores the bytes as a String variable.
+ */
+ private String bytes;
+
+ /**
+ The number of bytes to download.
+ */
+ private int numberOfBytes;
+
+ /**
+ Standard constructor.
+ */
+ public AnuRandom(){
+ this.in = null;
+ this.page = "";
+ this.bytes = "";
+ this.numberOfBytes = 0;
+ }
+
+ /**
+ Constructor.
+ @param numberOfBytes The number of bytes to download
+ */
+ public AnuRandom(int numberOfBytes){
+ this.numberOfBytes = numberOfBytes;
+ this.in = null;
+ this.page = "";
+ this.bytes = "";
+ }
+
+ /**
+ Set the number of bytes.
+ @param numberOfBytes The new number of bytes
+ */
+ public void setNumberOfBytes(int numberOfBytes){
+ this.numberOfBytes = numberOfBytes;
+ }
+
+ /**
+ Returns the number of bytes.
+ @return The number of bytes
+ */
+ public int getNumberOfBytes(){
+ return this.numberOfBytes;
+ }
+
+ /**
+ Runs to methods to download and parse the webpage.
+ Returns the bytes from the webpage.
+ @return The downloaded bytes
+ */
+ public byte[] getBytes(){
+ byte[] temp = new byte[this.numberOfBytes];
+ String store = "";
+
+ while(store.length() < this.numberOfBytes){
+ this.getPage();
+ this.parsePage();
+ store += this.bytes;
+ }
+ byte[] storeTemp = store.getBytes();
+ for(int i = 0; i < this.numberOfBytes; i++){
+ temp[i] = storeTemp[i];
+ }
+
+ return temp;
+ }
+
+ /**
+ Downloads the webpage and stores it in memory.
+ */
+ public void getPage(){
+ try{
+ URL u = new URL("http://150.203.48.55/RawChar.php");
+ this.in = new DataInputStream(new BufferedInputStream(u.openStream()));
+ String temp = "";
+ while ((temp = this.in.readLine()) != null){
+ this.page += temp;
+ }
+ }
+ catch(MalformedURLException e){
+ e.printStackTrace();
+ System.exit(1);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ System.exit(1);
+ }
+ finally{
+ try{
+ this.in.close();
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ Parses the random bytes from the webpage.
+ */
+ public void parsePage(){
+
+ int start;
+ int end;
+
+ start = this.page.indexOf("<table class=\"rng\" cellpadding=\"10\"> <tr><td>");
+ end = this.page.indexOf("</td></tr></table><br />", start);
+ start += 45;
+
+ this.bytes = this.page.substring(start, end);
+
+ }
+}
View
7 java/example.java
@@ -0,0 +1,7 @@
+public class example{
+ public static void main(String[] args){
+ AnuRandom random = new AnuRandom(2048);
+ String temp = new String(random.getBytes());
+ System.out.println(temp);
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.