From 7a8d6a812f4869a72dc6e7af102e1a5ecadbb85d Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Thu, 05 Apr 2018 18:32:56 +0000 Subject: [PATCH] file content bei collectFiles hinzugenommen --- src/de/uhilger/wbx/WbxUtils.java | 27 +++++++++++++++------------ src/logging.properties | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/de/uhilger/wbx/WbxUtils.java b/src/de/uhilger/wbx/WbxUtils.java index ff5dcf1..d10955b 100644 --- a/src/de/uhilger/wbx/WbxUtils.java +++ b/src/de/uhilger/wbx/WbxUtils.java @@ -59,7 +59,7 @@ public List<Inhalt> collectFiles(String requestUrl, String contextPath, - String relativePath, int maxTiefe, int maxAnzahl, long length) { + String relativePath, int maxTiefe, int maxAnzahl, int length) { Bild bild = new Bild(); //WbxUtils wu = new WbxUtils(); String basis = getJNDIParameter(WBX_FILE_BASE, WbxUtils.EMPTY_STRING); @@ -81,6 +81,9 @@ cont.setIsHidden(beitrag.isHidden()); cont.setLastModified(beitrag.lastModified()); cont.setLength(beitrag.length()); + if(length > 0) { + cont.setAbst(getFileContent(beitrag, length)); + } /* den 'https://..'-Teil bis vor dem @@ -110,24 +113,24 @@ return files; } - private String getFileContent(File file, long len) { + private String getFileContent(File file, int len) { try { StringBuffer readBuffer = new StringBuffer(); - byte[] buf = new byte[1024]; - long read = 0; - FileInputStream fis = new FileInputStream(file); - int bytesRead = fis.read(buf); - read += bytesRead; - while(read < len) { - readBuffer.append(buf); - bytesRead = fis.read(buf); + char[] buf = new char[1]; + FileReader fr = new FileReader(file); + int bytesRead = fr.read(buf); + int read = 0; + while(bytesRead > -1 && read < len) { read += bytesRead; + readBuffer.append(buf); + bytesRead = fr.read(buf); } - readBuffer.append(buf); + fr.close(); + logger.fine("read: " + read + ", readBuffer.len: " + readBuffer.length()); return readBuffer.toString(); } catch (Exception ex) { - Logger.getLogger(WbxUtils.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, ex.getMessage(), ex); return EMPTY_STRING; } } diff --git a/src/logging.properties b/src/logging.properties index fd8857a..e1a2c42 100644 --- a/src/logging.properties +++ b/src/logging.properties @@ -65,4 +65,4 @@ # messages: # com.xyz.foo.level = SEVERE de.uhilger.wbx.handlers = java.util.logging.ConsoleHandler -de.uhilger.wbx.level = INFO \ No newline at end of file +de.uhilger.wbx.level = FINER \ No newline at end of file -- Gitblit v1.9.3