public File returnFile() throws IOException { if (file == null) { deserialize(); } return file; }
public byte[] getContent() throws IOException { if (content == null) { serialize(); } return content; }
@Override public Object convertForGetModelEntries(Object object) { File file = (File) object; File zipFile = zipFile(file); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(zipFile); byte[] data = new byte[(int) zipFile.length()]; fileInputStream.read(data); FileWrapper wrapper = new FileWrapper(); wrapper.setFilename(file.getName()); wrapper.setContent(data); zipFile.delete(); return wrapper; } catch (FileNotFoundException ex) { LOGGER.error("File " + file.getAbsolutePath() + " was not found", ex); } catch (IOException ex) { LOGGER.error("IOException while reading from file " + file.getAbsolutePath(), ex); } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException ex) { LOGGER.error("Error while closing InputStream", ex); } } return null; }
@Override public Object convertForGetter(Object object) { FileWrapper wrapper = (FileWrapper) object; File f = new File(tempDir + File.separator + wrapper.getFilename() + ".zip"); FileOutputStream stream = null; try { f.createNewFile(); stream = new FileOutputStream(f); stream.write(wrapper.getContent()); stream.flush(); stream.close(); } catch (FileNotFoundException ex) { LOGGER.error("File " + f.getAbsolutePath() + " could not be created", ex); } catch (IOException ex) { LOGGER.error("IOException while writing the byte array of the wrapper to file " + f.getAbsolutePath(), ex); } finally { try { stream.close(); } catch (IOException ex) { LOGGER.error("Error while closing FileOutputStream", ex); } } return unzipFile(f, wrapper.getFilename()); }
public void deserialize() throws IOException { File f = new File(tempDir + File.separator + filename + ".zip"); FileOutputStream stream = null; try { f.createNewFile(); stream = new FileOutputStream(f); IOUtils.write(content, stream); stream.flush(); } finally { IOUtils.closeQuietly(stream); } file = unzipFile(f, filename); content = null; filename = null; }
public void serialize() throws IOException { File zipFile = zipFile(file); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(zipFile); byte[] data = new byte[(int) zipFile.length()]; fileInputStream.read(data); this.filename = file.getName(); this.content = data; FileUtils.forceDelete(zipFile); } finally { if (fileInputStream != null) { IOUtils.closeQuietly(fileInputStream); } } file = null; }
object.remove(propertyName); } else if (parameterType.equals(FileWrapper.class)) { FileWrapper wrapper = new FileWrapper(); String filename = object.getString(propertyName + FILEWRAPPER_FILENAME_SUFFIX); String content = (String) value; wrapper.setFilename(filename); wrapper.setContent(Base64.decodeBase64(content)); value = wrapper; object.remove(propertyName + FILEWRAPPER_FILENAME_SUFFIX);
try { FileWrapper wrapper = (FileWrapper) entry.getValue(); String content = Base64.encodeBase64String(wrapper.getContent()); object.putEDBObjectEntry(entry.getKey(), content, String.class); object.putEDBObjectEntry(entry.getKey() + FILEWRAPPER_FILENAME_SUFFIX, wrapper.getFilename(), String.class); } catch (IOException e) { LOGGER.error(e.getMessage());