| | |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStreamWriter; |
| | | import java.io.Reader; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.io.Writer; |
| | | import java.net.URLDecoder; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.Principal; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.filefilter.WildcardFileFilter; |
| | | import org.apache.commons.lang.StringEscapeUtils; |
| | | |
| | | /** |
| | | * Methoden zur Verwaltung von Dateien |
| | |
| | | try { |
| | | File targetFile = new File(getTargetDir(relPath), fileName); |
| | | |
| | | //reader = new InputStreamReader(new FileInputStream(targetFile), "UTF8"); |
| | | reader = new FileReader(targetFile); |
| | | reader = new InputStreamReader(new FileInputStream(targetFile), Charset.forName("UTF-8").newDecoder()); |
| | | //reader = new FileReader(targetFile); |
| | | StringBuffer buf = new StringBuffer(); |
| | | char[] readBuffer = new char[1024]; |
| | | int charsRead = reader.read(readBuffer); |
| | |
| | | } |
| | | } else { |
| | | if(operation == OP_MOVE) { |
| | | FileUtils.moveFileToDirectory(srcFile, targetDir, false); |
| | | String fname = srcFile.getName().toLowerCase(); |
| | | if(fname.endsWith(TNServlet.JPEG) || fname.endsWith(TNServlet.JPG) || fname.endsWith(TNServlet.PNG)) { |
| | | moveImgFilesToDirectory(srcFile, srcDir, targetDir, false); |
| | | } else { |
| | | FileUtils.moveFileToDirectory(srcFile, targetDir, false); |
| | | } |
| | | } else { |
| | | FileUtils.copyFileToDirectory(srcFile, targetDir); |
| | | } |
| | |
| | | logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private void moveImgFilesToDirectory(File srcFile, File srcDir, File targetDir, boolean createDestDir) throws IOException { |
| | | String fnameext = srcFile.getName(); |
| | | int dotpos = fnameext.lastIndexOf(DOT); |
| | | String fname = fnameext.substring(0, dotpos); |
| | | String ext = fnameext.substring(dotpos); |
| | | logger.fine("fname: " + fname + ", ext: " + ext); |
| | | FileFilter fileFilter = new WildcardFileFilter(fname + "*" + ext); |
| | | File[] files = srcDir.listFiles(fileFilter); |
| | | for (int i = 0; i < files.length; i++) { |
| | | logger.fine(files[i].getName()); |
| | | FileUtils.moveFileToDirectory(files[i], targetDir, createDestDir); |
| | | } |
| | | } |
| | | |
| | | public FileRef saveTextFileAs(String relPath, String fileName, String contents) { |
| | |
| | | FileRef savedFile = null; |
| | | try { |
| | | targetFile.createNewFile(); |
| | | FileWriter w = new FileWriter(targetFile); |
| | | //FileWriter w = new FileWriter(targetFile, Charset.forName("UTF-8")); |
| | | //w.write(StringEscapeUtils.unescapeHtml(contents)); |
| | | w.write(contents); |
| | | Writer w = new OutputStreamWriter(new FileOutputStream(targetFile), "UTF-8"); |
| | | //w.write(contents); |
| | | w.write(StringEscapeUtils.unescapeHtml(contents)); |
| | | w.flush(); |
| | | w.close(); |
| | | savedFile = new FileRef( |