diff --git a/LifeBlogger.iws b/LifeBlogger.iws
index e9f6c8a..487e028 100644
--- a/LifeBlogger.iws
+++ b/LifeBlogger.iws
@@ -112,19 +112,26 @@
encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES )
*
* @param serializableObject The object to encode
- * @options Specified options
+ * @param options Specified options
* @return The Base64-encoded object
* @see Base64#GZIP
* @see Base64#DONT_BREAK_LINES
@@ -470,7 +438,6 @@ public class Base64
* @param source The data to convert
* @param off Offset in array where conversion should begin
* @param len Length of data to convert
- * @param breakLines Break lines at 80 characters or less.
* @param options Specified options
* @see Base64#GZIP
* @see Base64#DONT_BREAK_LINES
@@ -578,30 +545,6 @@ public class Base64
/* ******** D E C O D I N G M E T H O D S ******** */
- /**
- * Decodes the first four bytes of array fourBytes
- * and returns an array up to three bytes long with the
- * decoded values.
- *
- * @param fourBytes the array with Base64 content
- * @return array with decoded values
- * @since 1.3
- */
- private static byte[] decode4to3( byte[] fourBytes )
- {
- byte[] outBuff1 = new byte[3];
- int count = decode4to3( fourBytes, 0, outBuff1, 0 );
- byte[] outBuff2 = new byte[ count ];
-
- for( int i = 0; i < count; i++ )
- outBuff2[i] = outBuff1[i];
-
- return outBuff2;
- }
-
-
-
-
/**
* Decodes four bytes from array source
* and writes the resulting bytes (up to three of them)
@@ -775,14 +718,11 @@ public class Base64
// Check to see if it's gzip-compressed
// GZIP Magic Two-Byte Number: 0x8b1f (35615)
- if( bytes.length >= 2 )
+ if( bytes != null && bytes.length >= 4 )
{
int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
- if(
- bytes != null && // In case decoding returned null
- bytes.length >= 4 && // Don't want to get ArrayIndexOutOfBounds exception
- java.util.zip.GZIPInputStream.GZIP_MAGIC == head )
+ if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head )
{
java.io.ByteArrayInputStream bais = null;
java.util.zip.GZIPInputStream gzis = null;
@@ -869,22 +809,196 @@ public class Base64
} // end decodeObject
+
+ /**
+ * Convenience method for encoding data to a file.
+ *
+ * @param dataToEncode byte array of data to encode in base64 form
+ * @param filename Filename for saving encoded data
+ * @return true if successful, false otherwise
+ *
+ * @since 2.1
+ */
+ public static boolean encodeToFile( byte[] dataToEncode, String filename )
+ {
+ boolean success = false;
+ Base64.OutputStream bos = null;
+ try
+ {
+ bos = new Base64.OutputStream(
+ new java.io.FileOutputStream( filename ), Base64.ENCODE );
+ bos.write( dataToEncode );
+ success = true;
+ } // end try
+ catch( java.io.IOException e )
+ {
+
+ success = false;
+ } // end catch: IOException
+ finally
+ {
+ try{ bos.close(); } catch( Exception e ){}
+ } // end finally
+
+ return success;
+ } // end encodeToFile
+
+
+ /**
+ * Convenience method for decoding data to a file.
+ *
+ * @param dataToDecode Base64-encoded data as a string
+ * @param filename Filename for saving decoded data
+ * @return true if successful, false otherwise
+ *
+ * @since 2.1
+ */
+ public static boolean decodeToFile( String dataToDecode, String filename )
+ {
+ boolean success = false;
+ Base64.OutputStream bos = null;
+ try
+ {
+ bos = new Base64.OutputStream(
+ new java.io.FileOutputStream( filename ), Base64.DECODE );
+ bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) );
+ success = true;
+ } // end try
+ catch( java.io.IOException e )
+ {
+ success = false;
+ } // end catch: IOException
+ finally
+ {
+ try{ bos.close(); } catch( Exception e ){}
+ } // end finally
+
+ return success;
+ } // end decodeToFile
+
+
+
+
+ /**
+ * Convenience method for reading a base64-encoded
+ * file and decoding it.
+ *
+ * @param filename Filename for reading encoded data
+ * @return decoded byte array or null if unsuccessful
+ *
+ * @since 2.1
+ */
+ public static byte[] decodeFromFile( String filename )
+ {
+ byte[] decodedData = null;
+ Base64.InputStream bis = null;
+ try
+ {
+ // Set up some useful variables
+ java.io.File file = new java.io.File( filename );
+ byte[] buffer = null;
+ int length = 0;
+ int numBytes = 0;
+
+ // Check for size of file
+ if( file.length() > Integer.MAX_VALUE )
+ {
+ System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." );
+ return null;
+ } // end if: file too big for int index
+ buffer = new byte[ (int)file.length() ];
+
+ // Open a stream
+ bis = new Base64.InputStream(
+ new java.io.BufferedInputStream(
+ new java.io.FileInputStream( file ) ), Base64.DECODE );
+
+ // Read until done
+ while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
+ length += numBytes;
+
+ // Save in a variable to return
+ decodedData = new byte[ length ];
+ System.arraycopy( buffer, 0, decodedData, 0, length );
+
+ } // end try
+ catch( java.io.IOException e )
+ {
+ System.err.println( "Error decoding from file " + filename );
+ } // end catch: IOException
+ finally
+ {
+ try{ bis.close(); } catch( Exception e) {}
+ } // end finally
+
+ return decodedData;
+ } // end decodeFromFile
+
+
+
+ /**
+ * Convenience method for reading a binary file
+ * and base64-encoding it.
+ *
+ * @param filename Filename for reading binary data
+ * @return base64-encoded string or null if unsuccessful
+ *
+ * @since 2.1
+ */
+ public static String encodeFromFile( String filename )
+ {
+ String encodedData = null;
+ Base64.InputStream bis = null;
+ try
+ {
+ // Set up some useful variables
+ java.io.File file = new java.io.File( filename );
+ byte[] buffer = new byte[ (int)(file.length() * 1.4) ];
+ int length = 0;
+ int numBytes = 0;
+
+ // Open a stream
+ bis = new Base64.InputStream(
+ new java.io.BufferedInputStream(
+ new java.io.FileInputStream( file ) ), Base64.ENCODE );
+
+ // Read until done
+ while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
+ length += numBytes;
+
+ // Save in a variable to return
+ encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING );
+
+ } // end try
+ catch( java.io.IOException e )
+ {
+ System.err.println( "Error encoding from file " + filename );
+ } // end catch: IOException
+ finally
+ {
+ try{ bis.close(); } catch( Exception e) {}
+ } // end finally
+
+ return encodedData;
+ } // end encodeFromFile
+
+
+
+
/* ******** I N N E R C L A S S I N P U T S T R E A M ******** */
/**
- * A {@link Base64#InputStream} will read data from another
- * {@link java.io.InputStream}, given in the constructor,
+ * A {@link Base64.InputStream} will read data from another
+ * java.io.InputStream, given in the constructor,
* and encode/decode to/from Base64 notation on the fly.
*
* @see Base64
- * @see java.io.FilterInputStream
* @since 1.3
*/
public static class InputStream extends java.io.FilterInputStream
{
- private int options; // Options specified
private boolean encode; // Encoding or decoding
private int position; // Current position in the buffer
private byte[] buffer; // Small buffer holding converted data
@@ -895,9 +1009,9 @@ public class Base64
/**
- * Constructs a {@link Base64#InputStream} in DECODE mode.
+ * Constructs a {@link Base64.InputStream} in DECODE mode.
*
- * @param in the {@link java.io.InputStream} from which to read data.
+ * @param in the java.io.InputStream from which to read data.
* @since 1.3
*/
public InputStream( java.io.InputStream in )
@@ -907,7 +1021,7 @@ public class Base64
/**
- * Constructs a {@link Base64#InputStream} in
+ * Constructs a {@link Base64.InputStream} in
* either ENCODE or DECODE mode.
* * Valid options:
@@ -920,7 +1034,7 @@ public class Base64 * Example:new Base64.InputStream( in, Base64.DECODE )
* * - * @param in the {@link java.io.InputStream} from which to read data. + * @param in the java.io.InputStream from which to read data. * @param options Specified options * @see Base64#ENCODE * @see Base64#DECODE @@ -930,11 +1044,8 @@ public class Base64 public InputStream( java.io.InputStream in, int options ) { super( in ); - this.options = options; this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; this.encode = (options & ENCODE) == ENCODE; - this.breakLines = breakLines; - this.encode = encode; this.bufferLength = encode ? 4 : 3; this.buffer = new byte[ bufferLength ]; this.position = -1; @@ -1065,7 +1176,7 @@ public class Base64 /** - * Calls {@link #read} repeatedly until the end of stream + * Calls {@link #read()} repeatedly until the end of stream * is reached or len bytes are read. * Returns number of bytes read into array or -1 if * end of stream is encountered. @@ -1109,17 +1220,15 @@ public class Base64 /** - * A {@link Base64#OutputStream} will write data to another - * {@link java.io.OutputStream}, given in the constructor, + * A {@link Base64.OutputStream} will write data to another + * java.io.OutputStream, given in the constructor, * and encode/decode to/from Base64 notation on the fly. * * @see Base64 - * @see java.io.FilterOutputStream * @since 1.3 */ public static class OutputStream extends java.io.FilterOutputStream { - private int options; private boolean encode; private int position; private byte[] buffer; @@ -1130,9 +1239,9 @@ public class Base64 private boolean suspendEncoding; /** - * Constructs a {@link Base64#OutputStream} in ENCODE mode. + * Constructs a {@link Base64.OutputStream} in ENCODE mode. * - * @param out the {@link java.io.OutputStream} to which data will be written. + * @param out the java.io.OutputStream to which data will be written. * @since 1.3 */ public OutputStream( java.io.OutputStream out ) @@ -1142,7 +1251,7 @@ public class Base64 /** - * Constructs a {@link Base64#OutputStream} in + * Constructs a {@link Base64.OutputStream} in * either ENCODE or DECODE mode. ** Valid options:
@@ -1154,7 +1263,7 @@ public class Base64 ** Example:
new Base64.OutputStream( out, Base64.ENCODE )
* - * @param out the {@link java.io.OutputStream} to which data will be written. + * @param out the java.io.OutputStream to which data will be written. * @param options Specified options. * @see Base64#ENCODE * @see Base64#DECODE @@ -1164,7 +1273,6 @@ public class Base64 public OutputStream( java.io.OutputStream out, int options ) { super( out ); - this.options = options; this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; this.encode = (options & ENCODE) == ENCODE; this.bufferLength = encode ? 3 : 4; @@ -1241,7 +1349,7 @@ public class Base64 /** - * Calls {@link #write} repeatedly until len + * Calls {@link #write(int)} repeatedly until len * bytes are written. * * @param theBytes array from which to read bytes diff --git a/src/net/thauvin/lifeblogger/LifeBlogger.java b/src/net/thauvin/lifeblogger/LifeBlogger.java index 3237656..3a0f965 100644 --- a/src/net/thauvin/lifeblogger/LifeBlogger.java +++ b/src/net/thauvin/lifeblogger/LifeBlogger.java @@ -73,6 +73,8 @@ public class LifeBlogger extends Thinlet private static final String JDBC_PREFIX = "jdbc:sqlite:/"; private static final String DATABASE = "\\DataBase\\NokiaLifeblogDataBase.db"; private static final String DEFAULT_ACTION = "mw"; + private static final String MIME_JPG = "image/jpeg"; + private static final String MIME_3GP = "video/3gpp"; private final Properties _prefs = new Properties(); private File _homeDir = new File(System.getProperty("user.home") + "\\My Documents\\NokiaLifeblogData"); private String _action; @@ -245,6 +247,10 @@ public class LifeBlogger extends Thinlet boolean first = true; int found = 0; + String[] info; + String oid; + String icon; + while (rs.next()) { ts = rs.getString("TimeStamp"); @@ -255,20 +261,22 @@ public class LifeBlogger extends Thinlet cell = Thinlet.create("cell"); thinlet.setString(cell, "text", name); - if (name.toLowerCase().endsWith("jpg")) + oid = rs.getString("HooverObjectID"); + info = fileInfo(oid); + icon = "/icon/text.gif"; + + if (MIME_JPG.equals(info[2])) { - thinlet.setIcon(cell, "icon", getIcon("/icon/image.gif")); + icon = "/icon/image.gif"; } - else if (name.toLowerCase().endsWith("3gp")) + else if (MIME_3GP.equals(info[2])) { - thinlet.setIcon(cell, "icon", getIcon("/icon/movie.gif")); - } - else - { - thinlet.setIcon(cell, "icon", getIcon("/icon/text.gif")); + icon = "/icon/movie.gif"; } - thinlet.putProperty(cell, "oid", rs.getString("HooverObjectID")); + thinlet.setIcon(cell, "icon", getIcon(icon)); + + thinlet.putProperty(cell, "oid", oid); thinlet.add(row, cell); cell = Thinlet.create("cell"); @@ -530,53 +538,50 @@ public class LifeBlogger extends Thinlet final String[] info = fileInfo(oid); - if (info[0].length() > 0) + if ((info[1] != null) && MIME_JPG.equals(info[2])) { - if ((info[2].length() > 0) && info[2].endsWith("jpeg")) + // Retrieve the jpg image + final BufferedImage in = ImageIO.read(new File(info[1])); + + final int maxDim = 200; + + final int height = in.getHeight(); + final int width = in.getWidth(); + + // Determine the scale. + double scale = (double) maxDim / (double) height; + + if (in.getWidth() > in.getHeight()) { - // Retrieve the jpg image - final BufferedImage in = ImageIO.read(new File(info[1])); - - final int maxDim = 200; - - final int height = in.getHeight(); - final int width = in.getWidth(); - - // Determine the scale. - double scale = (double) maxDim / (double) height; - - if (in.getWidth() > in.getHeight()) - { - scale = (double) maxDim / (double) width; - } - - int scaledW = (int) (scale * (double) width); - int scaledH = (int) (scale * (double) height); - - // Set the scale. - final AffineTransform tx = new AffineTransform(); - - if (scale <= 1.0d) - { - tx.scale(scale, scale); - } - else - { - scaledW = width; - scaledH = height; - } - - final BufferedImage out = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB); - - final Graphics2D g2d = out.createGraphics(); - g2d.drawImage(in, tx, null); - g2d.dispose(); - - final Object preview = parse("preview.xml"); - setString(preview, "text", info[0]); - setIcon(find(preview, "image"), "icon", out); - add(preview); + scale = (double) maxDim / (double) width; } + + int scaledW = (int) (scale * (double) width); + int scaledH = (int) (scale * (double) height); + + // Set the scale. + final AffineTransform tx = new AffineTransform(); + + if (scale <= 1.0d) + { + tx.scale(scale, scale); + } + else + { + scaledW = width; + scaledH = height; + } + + final BufferedImage out = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB); + + final Graphics2D g2d = out.createGraphics(); + g2d.drawImage(in, tx, null); + g2d.dispose(); + + final Object preview = parse("preview.xml"); + setString(preview, "text", info[0]); + setIcon(find(preview, "image"), "icon", out); + add(preview); } } } @@ -658,61 +663,6 @@ public class LifeBlogger extends Thinlet } } - /** - * Preforms the post/publish to blog action. - * - * @param dialog The post dialog, - * @param blogPanel The panel contaning the post data. - * @param publish Set totrue
to publish the post,false
otherwise. - * - * @throws IOException If an error occurs while performing the action. - */ - private void post(Object dialog, Object blogPanel, boolean publish) - throws IOException - { - final String host = getString(find(blogPanel, "host"), "text"); - final String blogID = getString(find(blogPanel, "blogid"), "text"); - final String login = getString(find(blogPanel, "login"), "text"); - final String password = getString(find(blogPanel, "password"), "text"); - final String entry = getString(find(blogPanel, "entry"), "text"); - - if (host.length() <= 0) - { - alert("Please specify a XML-RPC URL."); - } - else if (login.length() <= 0) - { - alert("Please specify a login name."); - } - else if (password.length() <= 0) - { - alert("Please specify a password."); - } - else if (entry.length() <= 0) - { - alert("Please specify a post entry."); - } - else if (blogID.length() <= 0) - { - alert("Please specify a blog ID."); - } - else - { - _prefs.put("blog-host", host); - _prefs.put("blog-login", login); - _prefs.put("blog-password", Base64.encodeBytes(password.getBytes(), Base64.DONT_BREAK_LINES)); - _prefs.put("blog-id", blogID); - - savePrefs(); - - closeDialog(dialog); - - final LifePost post = - new LifePost(this, host, blogID, login, password, getString(find(blogPanel, "entry"), "text"), publish); - post.start(); - } - } - // Displays an alert. private void alert(String message) { @@ -819,6 +769,61 @@ public class LifeBlogger extends Thinlet } } + /** + * Preforms the post/publish to blog action. + * + * @param dialog The post dialog, + * @param blogPanel The panel contaning the post data. + * @param publish Set totrue
to publish the post,false
otherwise. + * + * @throws IOException If an error occurs while performing the action. + */ + private void post(Object dialog, Object blogPanel, boolean publish) + throws IOException + { + final String host = getString(find(blogPanel, "host"), "text"); + final String blogID = getString(find(blogPanel, "blogid"), "text"); + final String login = getString(find(blogPanel, "login"), "text"); + final String password = getString(find(blogPanel, "password"), "text"); + final String entry = getString(find(blogPanel, "entry"), "text"); + + if (host.length() <= 0) + { + alert("Please specify a XML-RPC URL."); + } + else if (login.length() <= 0) + { + alert("Please specify a login name."); + } + else if (password.length() <= 0) + { + alert("Please specify a password."); + } + else if (entry.length() <= 0) + { + alert("Please specify a post entry."); + } + else if (blogID.length() <= 0) + { + alert("Please specify a blog ID."); + } + else + { + _prefs.put("blog-host", host); + _prefs.put("blog-login", login); + _prefs.put("blog-password", Base64.encodeBytes(password.getBytes(), Base64.DONT_BREAK_LINES)); + _prefs.put("blog-id", blogID); + + savePrefs(); + + closeDialog(dialog); + + final LifePost post = + new LifePost(this, host, blogID, login, password, getString(find(blogPanel, "entry"), "text"), publish); + post.start(); + } + } + // Saves the properties. private void savePrefs() { diff --git a/src/net/thauvin/lifeblogger/ReleaseInfo.java b/src/net/thauvin/lifeblogger/ReleaseInfo.java index d0b8346..cf416f9 100644 --- a/src/net/thauvin/lifeblogger/ReleaseInfo.java +++ b/src/net/thauvin/lifeblogger/ReleaseInfo.java @@ -1,5 +1,5 @@ /* Created by JReleaseInfo AntTask from Open Source Competence Group */ -/* Creation date Thu Aug 26 13:35:50 PDT 2004 */ +/* Creation date Wed Sep 29 05:39:16 PDT 2004 */ package net.thauvin.lifeblogger; import java.util.Date; @@ -12,28 +12,28 @@ import java.util.Date; public class ReleaseInfo { - /** buildDate (set during build process to 1093552550453L). */ - private static Date buildDate = new Date(1093552550453L); + /** buildDate (set during build process to 1096461556906L). */ + private static Date buildDate = new Date(1096461556906L); /** - * Get buildDate (set during build process to Thu Aug 26 13:35:50 PDT 2004). + * Get buildDate (set during build process to Wed Sep 29 05:39:16 PDT 2004). * @return Date buildDate */ public static final Date getBuildDate() { return buildDate; } /** - * Get buildNumber (set during build process to 118). + * Get buildNumber (set during build process to 1). * @return int buildNumber */ - public static final int getBuildNumber() { return 118; } + public static final int getBuildNumber() { return 1; } - /** version (set during build process to "0.1.0"). */ - private static String version = new String("0.1.0"); + /** version (set during build process to "0.1.1"). */ + private static String version = new String("0.1.1"); /** - * Get version (set during build process to "0.1.0"). + * Get version (set during build process to "0.1.1"). * @return String version */ public static final String getVersion() { return version; }