--- jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2009-09-26 11:43:16.000000000 -0600 +++ ../jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2010-04-13 11:57:37.976997583 -0600 @@ -392,7 +392,10 @@ for (Entry kv : zipPackages.entrySet()) { String classes = kv.getValue(); ostream.writeUTF(kv.getKey()); - ostream.writeUTF(classes); + // Make sure each package is not larger than 64k + for (String part : splitString(classes, 65535)) { + ostream.writeUTF(part); + } } ostream.close(); } catch (IOException ioe) { @@ -401,6 +404,45 @@ } /** + * Split up a string into several chunks based on a certain size + * + * The writeCacheFile method will use the writeUTF method on a + * DataOutputStream which only allows writing 64k chunks, so use + * this utility method to split it up + * + * @param str - The string to split up into chunks + * @param maxLength - The max size a string should be + * @return - An array of strings, each of which will not be larger than maxLength + */ + protected static String[] splitString(String str, int maxLength) { + if (str==null) { + return null; + } + // Determine number of chunks + int len = str.length(); + int fullChunks = len / maxLength; + boolean lastChunkEmpty = fullChunks*maxLength == len; + + // Setup size of array based on number of chunks + int size = fullChunks; + if (!lastChunkEmpty) { + size++; + } + + int i = 0; + String[] chunks = new String[size]; + for (i=0; i