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 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 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;
     }
   }

--
Gitblit v1.9.3