Author: nextgens
Date: 2008-07-16 10:08:09 +0000 (Wed, 16 Jul 2008)
New Revision: 21141

Modified:
   trunk/freenet/src/freenet/client/async/SingleFileInserter.java
   trunk/freenet/src/freenet/l10n/L10n.java
   trunk/freenet/src/freenet/support/io/BucketChainBucket.java
   trunk/freenet/src/freenet/support/io/BucketChainBucketFactory.java
   trunk/freenet/src/freenet/support/io/BucketTools.java
Log:
l10n: keep the short-code for internal purposes, export the long-name outside

Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java      
2008-07-16 09:48:23 UTC (rev 21140)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java      
2008-07-16 10:08:09 UTC (rev 21141)
@@ -14,6 +14,7 @@
 import freenet.keys.BaseClientKey;
 import freenet.keys.CHKBlock;
 import freenet.keys.FreenetURI;
+ import freenet.keys.NodeCHK;
 import freenet.keys.SSKBlock;
 import freenet.support.Logger;
 import freenet.support.OOMHandler;
@@ -21,6 +22,7 @@
 import freenet.support.api.Bucket;
 import freenet.support.compress.CompressionOutputSizeException;
 import freenet.support.compress.Compressor;
+import freenet.support.io.BucketChainBucketFactory;
 import freenet.support.io.BucketTools;

 /**
@@ -170,7 +172,7 @@
                                                
ctx.eventProducer.produceEvent(new StartedCompressionEvent(i));
                                        Compressor comp = 
Compressor.getCompressionAlgorithmByDifficulty(i);
                                        Bucket result;
-                                       result = comp.compress(origData, 
ctx.persistentBucketFactory, origData.size());
+                                       result = comp.compress(origData, new 
BucketChainBucketFactory(ctx.persistentBucketFactory, NodeCHK.BLOCK_SIZE), 
origData.size());
                                        if(result.size() < 
oneBlockCompressedSize) {
                                                bestCodec = comp;
                                                if(bestCompressedData != null)

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2008-07-16 09:48:23 UTC (rev 
21140)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2008-07-16 10:08:09 UTC (rev 
21141)
@@ -94,6 +94,7 @@
        * @throws MissingResourceException
        */
        public static void setLanguage(String selectedLanguage) throws 
MissingResourceException {
+               selectedLanguage = mapLanguageNameToLongName(selectedLanguage);
                synchronized (sync) {
                        Logger.normal(CLASS_NAME, "Changing the current 
language to : " + selectedLanguage);
                        currentClass = new L10n(selectedLanguage);
@@ -369,6 +370,24 @@
                return null;
        }

+       /**
+        * Map a language identifier to its corresponding long name
+        * 
+        * @param The name to look for
+        * @return The full text language name OR null if not found
+        */
+       public static String mapLanguageNameToLongName(String name) {
+               for(int i=0; i<AVAILABLE_LANGUAGES.length; i++) {
+                       String currentShortCode = AVAILABLE_LANGUAGES[i][0];
+                       String currentLongName = AVAILABLE_LANGUAGES[i][1];
+                       String currentCountryCodeName = 
AVAILABLE_LANGUAGES[i][2];
+                       
+                       if(currentShortCode.equalsIgnoreCase(name) || 
currentLongName.equalsIgnoreCase(name) || 
currentCountryCodeName.equalsIgnoreCase(name))
+                               return currentLongName;
+               }
+               return null;
+       }
+
        public static boolean isOverridden(String key) {
                synchronized(sync) {
                        if(translationOverride == null) return false;

Modified: trunk/freenet/src/freenet/support/io/BucketChainBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketChainBucket.java 2008-07-16 
09:48:23 UTC (rev 21140)
+++ trunk/freenet/src/freenet/support/io/BucketChainBucket.java 2008-07-16 
10:08:09 UTC (rev 21141)
@@ -41,7 +41,7 @@
                        list[i].free();
                }
        }
-       
+
        /** Equivalent to free(), but don't free the underlying buckets. */
        public void clear() {
                synchronized(this) {
@@ -49,7 +49,7 @@
                        buckets.clear();
                }
        }
-
+       
        public synchronized Bucket[] getBuckets() {
                return (Bucket[]) buckets.toArray(new Bucket[buckets.size()]);
        }

Modified: trunk/freenet/src/freenet/support/io/BucketChainBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketChainBucketFactory.java  
2008-07-16 09:48:23 UTC (rev 21140)
+++ trunk/freenet/src/freenet/support/io/BucketChainBucketFactory.java  
2008-07-16 10:08:09 UTC (rev 21141)
@@ -19,4 +19,4 @@
                return new BucketChainBucket(blockSize, factory);
        }

-}
+}
\ No newline at end of file

Modified: trunk/freenet/src/freenet/support/io/BucketTools.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BucketTools.java       2008-07-16 
09:48:23 UTC (rev 21140)
+++ trunk/freenet/src/freenet/support/io/BucketTools.java       2008-07-16 
10:08:09 UTC (rev 21141)
@@ -334,27 +334,24 @@
         * and the data written to them.
         * 
         * Note that this method will allocate a buffer of size splitSize.
-        * @param freeData 
+        * @param freeData
         * @throws IOException If there is an error creating buckets, reading 
from
         * the provided bucket, or writing to created buckets.
         */
        public static Bucket[] split(Bucket origData, int splitSize, 
BucketFactory bf, boolean freeData) throws IOException {
                if(origData instanceof FileBucket) {
-                       if(freeData) {
+                       if(freeData)
                                Logger.error(BucketTools.class, "Asked to free 
data when splitting a FileBucket ?!?!? Not freeing as this would clobber the 
split result...");
-                       }
                        return ((FileBucket)origData).split(splitSize);
                }
                if(origData instanceof BucketChainBucket) {
-                       BucketChainBucket data = (BucketChainBucket)origData;
+                       BucketChainBucket data = (BucketChainBucket) origData;
                        if(data.bucketSize == splitSize) {
-                               Bucket[] buckets = data.getBuckets();
                                if(freeData)
                                        data.clear();
-                               return buckets;
-                       } else {
-                               Logger.error(BucketTools.class, "Incompatible 
split size splitting a BucketChainBucket: his split size is "+data.bucketSize+" 
but mine is "+splitSize+" - we will copy the data, but this suggests a bug", 
new Exception("debug"));
-                       }
+                               return data.getBuckets();
+                       } else
+                               Logger.error(BucketTools.class, "Incompatible 
split size splitting a BucketChainBucket: his split size is " + data.bucketSize 
+ " but mine is " + splitSize + " - we will copy the data, but this suggests a 
bug", new Exception("debug"));
                }
                long length = origData.size();
                if(length > ((long)Integer.MAX_VALUE) * splitSize)


Reply via email to