Skip to content

Commit

Permalink
space added in utilmethods.java
Browse files Browse the repository at this point in the history
  • Loading branch information
0xc0d3r committed Aug 20, 2014
1 parent 6bbd4d5 commit cfd0c06
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/UtilMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static String getFileData(String fname) {
}
catch(Exception e) {
throw new RuntimeException("ERROR: File operation [email protected]_getFileData()");
//System.out.println("ERROR: File operation [email protected]_getFileData()");
//System.out.println("ERROR: File operation failed. @UtilMethods.java_getFileData()");
}
return text;
}
Expand Down
78 changes: 78 additions & 0 deletions src/util/UtilMethods.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package stegtool.util;
import java.io.FileInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.awt.Color;

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class UtilMethods {

//to get contents of a text file
public static String getFileData(String fname) {
String text = "";
int ch;
try {
InputStream is = new FileInputStream(fname);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
while( (ch = br.read()) != -1 ) {
text += ""+(char)ch;
}
}
catch(Exception e) {
throw new RuntimeException("ERROR: File operation [email protected]_getFileData()");
//System.out.println("ERROR: File operation [email protected]_getFileData()");
}
return text;
}

public static void setFileData(String name,String data) {
try {
File file = new File(name);
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(data);
bw.close();
}
catch(IOException e) {
throw new RuntimeException("\nError: Couldn't write data to file. UtilMethods.java@setFileData().");
//System.out.println("\nError: Couldn't write data to file. UtilMethods.java@setFileData().");
}
}

//to get binary format of given string
public static String textToBinary(String text) {
String bin = "";
StringBuffer sb = null;
for(int i=0;i<text.length();i++) {
sb = new StringBuffer(Integer.toBinaryString((int)text.charAt(i)));
bin += binaryLeftPadding(sb);
}
return bin;
}

//to left padding the binary numbers
public static String binaryLeftPadding(StringBuffer bin) {
while(bin.length() < 8) {
bin.insert(0,"0");
}
return bin.toString();
}

//to get text from given binary
public static String binaryToText(String bin) {
String text = null;
for(int i=0;i<bin.length()-8;i+=8) {
int chr = Integer.parseInt(bin.substring(i,i+8),2);
text += (char)chr;
if(text.contains("~~~")) break;
}
return text;
}
}

0 comments on commit cfd0c06

Please sign in to comment.