List of usage examples for com.liferay.portal.kernel.dao.jdbc OutputBlob OutputBlob
public OutputBlob(InputStream inputStream, long length)
From source file:com.liferay.document.library.content.service.impl.DLContentLocalServiceImpl.java
License:Open Source License
@Override public DLContent addContent(long companyId, long repositoryId, String path, String version, byte[] bytes) { long contentId = counterLocalService.increment(); DLContent dlContent = dlContentPersistence.create(contentId); dlContent.setCompanyId(companyId);//from w w w.j a va2 s.c o m dlContent.setRepositoryId(repositoryId); dlContent.setPath(path); dlContent.setVersion(version); UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(bytes); OutputBlob dataOutputBlob = new OutputBlob(unsyncByteArrayInputStream, bytes.length); dlContent.setData(dataOutputBlob); dlContent.setSize(bytes.length); dlContentPersistence.update(dlContent); return dlContent; }
From source file:com.liferay.document.library.content.service.impl.DLContentLocalServiceImpl.java
License:Open Source License
@Override public DLContent addContent(long companyId, long repositoryId, String path, String version, InputStream inputStream, long size) { DLContent dlContent = null;/*from ww w . j a v a 2s. c o m*/ try (InputStream is = inputStream) { long contentId = counterLocalService.increment(); dlContent = dlContentPersistence.create(contentId); dlContent.setCompanyId(companyId); dlContent.setRepositoryId(repositoryId); dlContent.setPath(path); dlContent.setVersion(version); OutputBlob dataOutputBlob = new OutputBlob(is, size); dlContent.setData(dataOutputBlob); dlContent.setSize(size); dlContentPersistence.update(dlContent); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe, ioe); } } return dlContent; }
From source file:com.liferay.document.library.content.service.persistence.test.DLContentPersistenceTest.java
License:Open Source License
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); DLContent newDLContent = _persistence.create(pk); newDLContent.setGroupId(RandomTestUtil.nextLong()); newDLContent.setCompanyId(RandomTestUtil.nextLong()); newDLContent.setRepositoryId(RandomTestUtil.nextLong()); newDLContent.setPath(RandomTestUtil.randomString()); newDLContent.setVersion(RandomTestUtil.randomString()); String newDataString = RandomTestUtil.randomString(); byte[] newDataBytes = newDataString.getBytes("UTF-8"); Blob newDataBlob = new OutputBlob(new ByteArrayInputStream(newDataBytes), newDataBytes.length); newDLContent.setData(newDataBlob);//from w w w. j a v a2 s. com newDLContent.setSize(RandomTestUtil.nextLong()); _dlContents.add(_persistence.update(newDLContent)); DLContent existingDLContent = _persistence.findByPrimaryKey(newDLContent.getPrimaryKey()); Assert.assertEquals(existingDLContent.getContentId(), newDLContent.getContentId()); Assert.assertEquals(existingDLContent.getGroupId(), newDLContent.getGroupId()); Assert.assertEquals(existingDLContent.getCompanyId(), newDLContent.getCompanyId()); Assert.assertEquals(existingDLContent.getRepositoryId(), newDLContent.getRepositoryId()); Assert.assertEquals(existingDLContent.getPath(), newDLContent.getPath()); Assert.assertEquals(existingDLContent.getVersion(), newDLContent.getVersion()); Blob existingData = existingDLContent.getData(); Assert.assertTrue(Arrays.equals(existingData.getBytes(1, (int) existingData.length()), newDataBytes)); Assert.assertEquals(existingDLContent.getSize(), newDLContent.getSize()); }
From source file:com.liferay.document.library.content.service.persistence.test.DLContentPersistenceTest.java
License:Open Source License
protected DLContent addDLContent() throws Exception { long pk = RandomTestUtil.nextLong(); DLContent dlContent = _persistence.create(pk); dlContent.setGroupId(RandomTestUtil.nextLong()); dlContent.setCompanyId(RandomTestUtil.nextLong()); dlContent.setRepositoryId(RandomTestUtil.nextLong()); dlContent.setPath(RandomTestUtil.randomString()); dlContent.setVersion(RandomTestUtil.randomString()); String dataString = RandomTestUtil.randomString(); byte[] dataBytes = dataString.getBytes("UTF-8"); Blob dataBlob = new OutputBlob(new ByteArrayInputStream(dataBytes), dataBytes.length); dlContent.setData(dataBlob);/*from w w w . ja v a 2 s .c o m*/ dlContent.setSize(RandomTestUtil.nextLong()); _dlContents.add(_persistence.update(dlContent)); return dlContent; }
From source file:com.liferay.portlet.documentlibrary.service.impl.DLContentLocalServiceImpl.java
License:Open Source License
public DLContent addContent(long companyId, long repositoryId, String path, String version, byte[] bytes) throws SystemException { long contentId = counterLocalService.increment(); DLContent dlContent = dlContentPersistence.create(contentId); dlContent.setCompanyId(companyId);/*from w w w . ja va 2s . c o m*/ dlContent.setRepositoryId(repositoryId); dlContent.setPath(path); dlContent.setVersion(version); UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(bytes); OutputBlob dataOutputBlob = new OutputBlob(unsyncByteArrayInputStream, bytes.length); dlContent.setData(dataOutputBlob); dlContent.setSize(bytes.length); dlContentPersistence.update(dlContent, false); return dlContent; }
From source file:com.liferay.portlet.documentlibrary.service.impl.DLContentLocalServiceImpl.java
License:Open Source License
public DLContent addContent(long companyId, long repositoryId, String path, String version, InputStream inputStream, long size) throws SystemException { try {//from w w w . j a v a2 s . c o m long contentId = counterLocalService.increment(); DLContent dlContent = dlContentPersistence.create(contentId); dlContent.setCompanyId(companyId); dlContent.setRepositoryId(repositoryId); dlContent.setPath(path); dlContent.setVersion(version); OutputBlob dataOutputBlob = new OutputBlob(inputStream, size); dlContent.setData(dataOutputBlob); dlContent.setSize(size); dlContentPersistence.update(dlContent, false); return dlContent; } finally { StreamUtil.cleanUp(inputStream); } }
From source file:com.liferay.portlet.documentlibrary.service.persistence.DLContentPersistenceTest.java
License:Open Source License
public void testUpdateExisting() throws Exception { long pk = nextLong(); DLContent newDLContent = _persistence.create(pk); newDLContent.setGroupId(nextLong()); newDLContent.setCompanyId(nextLong()); newDLContent.setRepositoryId(nextLong()); newDLContent.setPath(randomString()); newDLContent.setVersion(randomString()); String newDataString = randomString(); byte[] newDataBytes = newDataString.getBytes(StringPool.UTF8); Blob newDataBlob = new OutputBlob(new UnsyncByteArrayInputStream(newDataBytes), newDataBytes.length); newDLContent.setData(newDataBlob);// w ww . j av a2 s . co m newDLContent.setSize(nextLong()); _persistence.update(newDLContent, false); DLContent existingDLContent = _persistence.findByPrimaryKey(newDLContent.getPrimaryKey()); assertEquals(existingDLContent.getContentId(), newDLContent.getContentId()); assertEquals(existingDLContent.getGroupId(), newDLContent.getGroupId()); assertEquals(existingDLContent.getCompanyId(), newDLContent.getCompanyId()); assertEquals(existingDLContent.getRepositoryId(), newDLContent.getRepositoryId()); assertEquals(existingDLContent.getPath(), newDLContent.getPath()); assertEquals(existingDLContent.getVersion(), newDLContent.getVersion()); Blob existingData = existingDLContent.getData(); assertTrue(Arrays.equals(existingData.getBytes(1, (int) existingData.length()), newDataBytes)); assertEquals(existingDLContent.getSize(), newDLContent.getSize()); }
From source file:com.liferay.portlet.documentlibrary.service.persistence.DLContentPersistenceTest.java
License:Open Source License
protected DLContent addDLContent() throws Exception { long pk = nextLong(); DLContent dlContent = _persistence.create(pk); dlContent.setGroupId(nextLong());//from w ww .java2s. c o m dlContent.setCompanyId(nextLong()); dlContent.setRepositoryId(nextLong()); dlContent.setPath(randomString()); dlContent.setVersion(randomString()); String dataString = randomString(); byte[] dataBytes = dataString.getBytes(StringPool.UTF8); Blob dataBlob = new OutputBlob(new UnsyncByteArrayInputStream(dataBytes), dataBytes.length); dlContent.setData(dataBlob); dlContent.setSize(nextLong()); _persistence.update(dlContent, false); return dlContent; }
From source file:edu.ucla.macroscope.textlibrary.service.impl.MacroscopeDocumentServiceImpl.java
License:Open Source License
@JSONWebService(method = "POST") public String uploadFile(File file) { try {//from w w w .j a va 2s .co m MacroscopeDocument md = MacroscopeDocumentLocalServiceUtil .createMacroscopeDocument(CounterLocalServiceUtil.increment()); OutputBlob contentBlob = new OutputBlob(new FileInputStream(file), file.length()); md.setTitle(file.getName()); md.setContent(contentBlob); md.setNew(true); MacroscopeDocumentLocalServiceUtil.addMacroscopeDocument(md); return md.getPrimaryKey() + ""; } catch (SystemException ex) { return ex.toString(); } catch (FileNotFoundException ex) { System.out.println("File not found: how did this happen?"); return ex.toString(); } }
From source file:net.indaba.lostandfound.service.impl.LFImageServiceImpl.java
License:Open Source License
public LFImage addLFImage(String imageBase64String, long itemId, ServiceContext serviceContext) { String imageString;/*from ww w . j a va 2 s . c o m*/ String imageStrings[] = imageBase64String.split("base64,"); if (imageStrings.length > 1) { imageString = imageStrings[1]; } else { imageString = imageBase64String; } ByteArrayInputStream imageBase64 = new ByteArrayInputStream(imageString.getBytes(StandardCharsets.UTF_8)); OutputBlob dataOutputBlob = new OutputBlob(imageBase64, imageString.length()); LFImage lfImage = LFImageLocalServiceUtil.createLFImage(CounterLocalServiceUtil.increment()); lfImage.setItemId(itemId); lfImage.setImage(dataOutputBlob); return LFImageLocalServiceUtil.addLFImage(lfImage, serviceContext); }