Source code cleanup
parent
44b962a60d
commit
d0ca6931ec
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2011 YAMJ Members
|
||||
* http://code.google.com/p/moviejukebox/people/list
|
||||
*
|
||||
* Web: http://code.google.com/p/moviejukebox/
|
||||
*
|
||||
* This software is licensed under a Creative Commons License
|
||||
* See this page: http://code.google.com/p/moviejukebox/wiki/License
|
||||
*
|
||||
* For any reuse or distribution, you must make clear to others the
|
||||
* license terms of this work.
|
||||
*/
|
||||
package com.moviejukebox.themoviedb.tools;
|
||||
|
||||
public class Base64 {
|
||||
private static final String base64code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
public static String base64Encode(String string) {
|
||||
String unEncoded = string; // Copy the string so we can modify it
|
||||
StringBuffer encoded = new StringBuffer();
|
||||
// determine how many padding bytes to add to the output
|
||||
int paddingCount = (3 - (unEncoded.length() % 3)) % 3;
|
||||
// add any necessary padding to the input
|
||||
unEncoded += "\0\0".substring(0, paddingCount);
|
||||
// process 3 bytes at a time, churning out 4 output bytes
|
||||
// worry about CRLF insertions later
|
||||
for (int i = 0; i < unEncoded.length(); i += 3) {
|
||||
int j = (unEncoded.charAt(i) << 16) + (unEncoded.charAt(i + 1) << 8) + unEncoded.charAt(i + 2);
|
||||
encoded.append(base64code.charAt((j >> 18) & 0x3f) + base64code.charAt((j >> 12) & 0x3f) + base64code.charAt((j >> 6) & 0x3f)
|
||||
+ base64code.charAt(j & 0x3f));
|
||||
}
|
||||
// replace encoded padding nulls with "="
|
||||
// return encoded;
|
||||
return "Basic " + encoded.toString();
|
||||
}
|
||||
}
|
||||
@ -1,43 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2011 YAMJ Members
|
||||
* http://code.google.com/p/moviejukebox/people/list
|
||||
*
|
||||
* http://code.google.com/p/moviejukebox/people/list
|
||||
*
|
||||
* Web: http://code.google.com/p/moviejukebox/
|
||||
*
|
||||
*
|
||||
* This software is licensed under a Creative Commons License
|
||||
* See this page: http://code.google.com/p/moviejukebox/wiki/License
|
||||
*
|
||||
* For any reuse or distribution, you must make clear to others the
|
||||
* license terms of this work.
|
||||
*
|
||||
* For any reuse or distribution, you must make clear to others the
|
||||
* license terms of this work.
|
||||
*/
|
||||
package com.moviejukebox.themoviedb.tools;
|
||||
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class LogFormatter extends java.util.logging.Formatter
|
||||
{
|
||||
public class LogFormatter extends java.util.logging.Formatter {
|
||||
|
||||
private static String apiKey = null;
|
||||
private static String EOL = (String)java.security.AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
private static final String EOL = (String) java.security.AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
|
||||
@Override
|
||||
public Object run() {
|
||||
return System.getProperty("line.separator");
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public synchronized String format(LogRecord logRecord) {
|
||||
String logMessage = logRecord.getMessage();
|
||||
|
||||
logMessage = "[TheMovieDb API] " + logMessage.replace(apiKey, "[APIKEY]") + EOL;
|
||||
|
||||
|
||||
Throwable thrown = logRecord.getThrown();
|
||||
if (thrown != null) {
|
||||
logMessage = logMessage + thrown.toString();
|
||||
if (thrown != null) {
|
||||
logMessage = logMessage + thrown.toString();
|
||||
}
|
||||
return logMessage;
|
||||
}
|
||||
|
||||
|
||||
public void addApiKey(String apiKey) {
|
||||
LogFormatter.apiKey = apiKey;
|
||||
LogFormatter.apiKey = apiKey;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue