29.07.2013 Views

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

{<br />

}<br />

//Make the normal log-file<br />

log(s,runningAplication);<br />

System.out.print(s);<br />

private static void log(String m,String filename)<br />

{<br />

//Husk filendelsen .log<br />

File f = new File(Config.logFolderPath + filename + ".log");<br />

try<br />

{<br />

BufferedWriter writer = new BufferedWriter(new FileWriter(f,true));<br />

writer.write(m);<br />

writer.close();<br />

}<br />

catch(IOException ex)<br />

{<br />

System.out.println("Debugger: Error while trying to log to "+filename);<br />

}<br />

}<br />

private static class DebugDefinition<br />

{<br />

public String className;<br />

public int debuglevel;<br />

}<br />

public DebugDefinition(String className, int debuglevel)<br />

{<br />

this.className = className;<br />

this.debuglevel = debuglevel;<br />

}<br />

10.5.5 FileHandler<br />

package <strong>Spam</strong>Cash.Utilities;<br />

import java.io.*;<br />

import java.security.cert.CertificateEncodingException;<br />

import java.nio.charset.Charset;<br />

import java.security.cert.Certificate;<br />

import java.security.cert.CertificateFactory;<br />

import java.security.cert.CertificateException;<br />

import <strong>Spam</strong>Cash.Utilities.Debugger;<br />

public class FileHandler<br />

{<br />

public static byte[] readBytes(File file) throws IOException<br />

{<br />

InputStream is = new FileInputStream(file);<br />

// Get the size <strong>of</strong> the file<br />

long length = file.length();<br />

// Create the byte array to hold the data<br />

byte[] bytes = new byte[(int) length];<br />

// Read in the bytes<br />

int <strong>of</strong>fset = 0;<br />

int numRead = 0;<br />

while(<strong>of</strong>fset < bytes.length<br />

{<br />

}<br />

&& (numRead = is.read(bytes, <strong>of</strong>fset, bytes.length - <strong>of</strong>fset)) >= 0)<br />

<strong>of</strong>fset += numRead;<br />

403

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!