We Recommend

Building Websites with TYPO3 Building Websites with TYPO3
Follow a clear path through the power and complexity of TYPO3 to get started, and build your own TYPO3 website This book is a fast paced tutorial to creating a website using TYPO3. If you have never used TYPO3, or even any web content management system before, then you need not look further than this book as it walks you through each step to create your own TYPO3 site.


Ballyhoo


Posted By

karelklic on 02/27/08


Tagged

file utf8 zip diacritics


Versions (?)


Compresses all the files in some directory recursively (zip); solves diacritics problems


Published in: Groovy 


Removes diacritics from file name before adding it to the archive. Archive file name retains diacritics.


  1. import java.util.zip.*
  2. import java.text.*
  3.  
  4. def toBase2(String sText){
  5. boolean bChar = true
  6. int iSize = sText.length()
  7. int i = 0
  8. String sAux = ""
  9.  
  10. for (i=0; i < iSize; i++) {
  11. String sLetter = sText.charAt(i)
  12. sLetter = Normalizer.normalize(sLetter, Normalizer.Form.NFD)
  13. try{
  14. byte[] bLetter = (new String(sLetter)).getBytes("UTF-8")
  15. char cLetter = (char) bLetter[0]
  16. sAux += "" + cLetter
  17. }
  18. }
  19. }
  20. return sAux
  21. }
  22.  
  23. new File(args[0]).eachFileRecurse() { f ->
  24. if (f ==~ /.*zip$/ || !f.isFile()) return
  25. name = f.toString()
  26. zipname = name.substring(0, name.lastIndexOf(".")) + ".zip"
  27. nameInZip = toBase2(name.substring(name.lastIndexOf("\\") + 1))
  28. println nameInZip
  29. out.putNextEntry(new ZipEntry(nameInZip))
  30.  
  31. // nejde napsat out.write(f.readbytes()), protoze na 100mb
  32. // souboru to zahlasi out of memory
  33. ins = f.newInputStream()
  34. buffer = new byte[18024]
  35. while ((len = ins.read(buffer)) > 0)
  36. out.write(buffer, 0, len)
  37.  
  38. out.closeEntry()
  39. out.close()
  40. }

Report this snippet 

You need to login to post a comment.