001/* 002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Florent Guillaume 011 */ 012package org.nuxeo.ecm.core.opencmis.impl.server; 013 014import java.io.IOException; 015import java.io.InputStream; 016import java.math.BigInteger; 017import java.util.GregorianCalendar; 018import java.util.List; 019 020import org.apache.chemistry.opencmis.commons.data.CacheHeaderContentStream; 021import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement; 022import org.apache.chemistry.opencmis.commons.data.ContentStream; 023import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream; 024import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException; 025import org.nuxeo.ecm.core.api.Blob; 026 027/** 028 * Nuxeo implementation of a CMIS {@link ContentStream}, backed by a {@link Blob}. 029 */ 030public class NuxeoContentStream implements CacheHeaderContentStream, LastModifiedContentStream { 031 032 public static long LAST_MODIFIED; 033 034 protected final Blob blob; 035 036 protected final GregorianCalendar lastModified; 037 038 public NuxeoContentStream(Blob blob, GregorianCalendar lastModified) { 039 this.blob = blob; 040 this.lastModified = lastModified; 041 } 042 043 @Override 044 public long getLength() { 045 return blob.getLength(); 046 } 047 048 @Override 049 public BigInteger getBigLength() { 050 return BigInteger.valueOf(blob.getLength()); 051 } 052 053 @Override 054 public String getMimeType() { 055 return blob.getMimeType(); 056 } 057 058 @Override 059 public String getFileName() { 060 return blob.getFilename(); 061 } 062 063 @Override 064 public InputStream getStream() { 065 try { 066 return blob.getStream(); 067 } catch (IOException e) { 068 throw new CmisRuntimeException("Failed to get stream", e); 069 } 070 } 071 072 @Override 073 public List<CmisExtensionElement> getExtensions() { 074 return null; 075 } 076 077 @Override 078 public void setExtensions(List<CmisExtensionElement> extensions) { 079 throw new UnsupportedOperationException(); 080 } 081 082 @Override 083 public String getCacheControl() { 084 return null; 085 } 086 087 @Override 088 public String getETag() { 089 return blob.getDigest(); 090 } 091 092 @Override 093 public GregorianCalendar getExpires() { 094 return null; 095 } 096 097 @Override 098 public GregorianCalendar getLastModified() { 099 LAST_MODIFIED = lastModified == null ? 0 : lastModified.getTimeInMillis(); 100 return lastModified; 101 } 102 103}