import org.argeo.slc.SlcException;
public class FileAttachmentsStorage implements AttachmentsStorage {
- private File attachmentsDirectory = new File(System
- .getProperty("java.io.tmpdir")
- + File.separator + "slcAttachments");
+ private File attachmentsDirectory;
+
+ public FileAttachmentsStorage() {
+ String osgiInstanceArea = System.getProperty("osgi.instance.area");
+ if (osgiInstanceArea != null) {
+ if (osgiInstanceArea.startsWith("file:"))
+ osgiInstanceArea = osgiInstanceArea.substring("file:".length());
+ attachmentsDirectory = new File(osgiInstanceArea + File.separator
+ + "slcAttachments");
+ }
+
+ if (attachmentsDirectory == null) {
+ String tempDir = System.getProperty("java.io.tmpdir");
+ attachmentsDirectory = new File(tempDir + File.separator
+ + "slcAttachments");
+ }
+ }
public void retrieveAttachment(Attachment attachment,
OutputStream outputStream) {
try {
byte[] buffer = new byte[1024 * 1024];
in = new FileInputStream(file);
- while (in.read(buffer) >= 0) {
- outputStream.write(buffer);
+ int read = -1;
+ while ((read = in.read(buffer)) >= 0) {
+ outputStream.write(buffer, 0, read);
}
} catch (IOException e) {
throw new SlcException("Cannot write attachment " + attachment