在Eclipse中,我试图在每个文件的末尾显示zip文件的内容是[] [] [] [] [] [] [] [] [] []。有人可以解释一下吗?
def uploadTheme(String themeName, def inputStream) {
def themeNameUp = themeName.toUpperCase()
def themeKey = this.prefix + themeNameUp
if (redisService.exists(themeKey) && inputStream) {
ZipInputStream zipFile = new ZipInputStream(inputStream)
ZipEntry zipEntry = zipFile.nextEntry
while (zipEntry) {
def key = zipEntry.name
if (key.startsWith(this.widgetPrefix) || key.startsWith(this.templatePrefix)) {
byte[] data = new byte[4096]
StringBuffer zipContent = new StringBuffer()
int length = zipFile.read(data, 0, data.size())
while (length != -1) {
zipContent << new String(data)
length = zipFile.read(data, 0, data.size())
}
if (key.endsWith(":data")) {
def prevData = redisService.hget(themeKey, key)
if (prevData) {
historyService.addHistory(themeNameUp + ":" + key[0..-6], prevData)
}
}
redisService.hset(themeKey, key, zipContent.toString())
}
zipFile.closeEntry()
zipEntry = zipFile.nextEntry
}
zipFile.close()
}
答案 0 :(得分:0)
zipContent << new String(data)
应该是
zipContent << new String(data, 0, length)
长度是实际读取的数量。最后长度小于数据的大小。
请注意,创建的字符串: