diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java index 20cb033785..bfe7675c81 100644 --- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java +++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/lob/CDOBlob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2015, 2016, 2019 Eike Stepper (Loehne, Germany) and others. + * Copyright (c) 2011, 2012, 2015, 2016, 2019, 2021, 2022 Eike Stepper (Loehne, Germany) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,8 +12,13 @@ package org.eclipse.emf.cdo.common.lob; import org.eclipse.emf.cdo.spi.common.CDOLobStoreImpl; +import org.eclipse.net4j.util.HexUtil; import org.eclipse.net4j.util.io.ExtendedDataInput; +import org.eclipse.net4j.util.io.IOUtil; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -35,6 +40,22 @@ public final class CDOBlob extends CDOLob<InputStream> super(contents, store); } + /** + * @since 4.13 + */ + public CDOBlob(byte[] contents, CDOLobStore store) throws IOException + { + super(new ByteArrayInputStream(contents), store); + } + + /** + * @since 4.13 + */ + public CDOBlob(String contents, CDOLobStore store) throws IOException + { + super(new ByteArrayInputStream(HexUtil.hexToBytes(contents)), store); + } + CDOBlob(byte[] id, long size) { super(id, size); @@ -46,11 +67,47 @@ public final class CDOBlob extends CDOLob<InputStream> } @Override + public File getStoreFile() + { + return getStore().getBinaryFile(getID()); + } + + @Override public InputStream getContents() throws IOException { return getStore().getBinary(this); } + /** + * @since 4.13 + */ + public byte[] getBytes() throws IOException + { + InputStream inputStream = null; + + try + { + inputStream = getContents(); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + IOUtil.copy(inputStream, outputStream); + return outputStream.toByteArray(); + } + finally + { + IOUtil.close(inputStream); + } + } + + /** + * @since 4.13 + */ + @Override + public String getString() throws IOException + { + return HexUtil.bytesToHex(getBytes()); + } + @Override protected CDOLobInfo put(InputStream contents) throws IOException { |