/** * @see javax.jcr.Value#getStream() */ public InputStream getStream() throws IllegalStateException, RepositoryException { if (stream == null) { if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // qualified name/path value needs to be resolved stream = new ByteArrayInputStream(getString().getBytes(StandardCharsets.UTF_8)); } else { stream = qvalue.getStream(); } } return stream; }
/** * @see javax.jcr.Value#getStream() */ public InputStream getStream() throws IllegalStateException, RepositoryException { if (stream == null) { if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // qualified name/path value needs to be resolved stream = new ByteArrayInputStream(getString().getBytes(StandardCharsets.UTF_8)); } else { stream = qvalue.getStream(); } } return stream; }
private HttpEntity getEntity(QValue value) throws RepositoryException { // SPI value must be converted to jcr value int type = value.getType(); String contentType = JcrValueType.contentTypeFromType(type); HttpEntity ent; switch (type) { case PropertyType.NAME: case PropertyType.PATH: String str = ValueFormat.getJCRString(value, resolver); ent = new StringEntity(str, ContentType.create(contentType, "UTF-8")); break; case PropertyType.BINARY: InputStream in = value.getStream(); ent = new InputStreamEntity(in, ContentType.create(contentType)); break; default: str = value.getString(); ent = new StringEntity(str, ContentType.create(contentType, "UTF-8")); break; } return ent; }
private HttpEntity getEntity(QValue value) throws RepositoryException { // SPI value must be converted to jcr value int type = value.getType(); String contentType = JcrValueType.contentTypeFromType(type); HttpEntity ent; switch (type) { case PropertyType.NAME: case PropertyType.PATH: String str = ValueFormat.getJCRString(value, resolver); ent = new StringEntity(str, ContentType.create(contentType, "UTF-8")); break; case PropertyType.BINARY: InputStream in = value.getStream(); ent = new InputStreamEntity(in, ContentType.create(contentType)); break; default: str = value.getString(); ent = new StringEntity(str, ContentType.create(contentType, "UTF-8")); break; } return ent; }
private static void assertDisposed(QValue v) { try { v.getStream(); fail("Value should have been disposed."); } catch (Exception e) { // success (interpret this as value was disposed) } }
public void testBinaryFromFile() throws RepositoryException, IOException { File f = File.createTempFile("QValueFactoryImplTest", ".txt"); f.deleteOnExit(); FileWriter fw = new FileWriter(f); fw.write("abc"); fw.close(); QValue v = factory.create(f); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 3); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testBinaryFromFile() throws RepositoryException, IOException { File f = File.createTempFile("QValueFactoryImplTest", ".txt"); f.deleteOnExit(); FileWriter fw = new FileWriter(f); fw.write("abc"); fw.close(); QValue v = factory.create(f); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(3, v.getLength()); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
/** * {@inheritDoc} */ public InputStream getStream() throws IllegalStateException, RepositoryException { setStreamConsumed(); if (stream == null) { if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // needs namespace mapping try { String l_s = getType() == PropertyType.NAME ? resolver.getJCRName(qvalue.getName()) : resolver.getJCRPath(qvalue.getPath()); stream = new ByteArrayInputStream(l_s.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { throw new RepositoryException(ex); } } else { stream = qvalue.getStream(); } } return stream; }
public void testEmptyBinaryFromFile() throws RepositoryException, IOException { File f = File.createTempFile("QValueFactoryImplTest", ".txt"); f.deleteOnExit(); QValue v = factory.create(f); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 0); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testEmptyBinaryFromFile() throws RepositoryException, IOException { File f = File.createTempFile("QValueFactoryImplTest", ".txt"); f.deleteOnExit(); QValue v = factory.create(f); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(0, v.getLength()); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testEmptyBinaryFromInputStream() throws RepositoryException, IOException { InputStream in = new ByteArrayInputStream(new byte[0]); QValue v = factory.create(in); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 0); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testBinaryFromInputStream() throws RepositoryException, IOException { InputStream in = new ByteArrayInputStream(new byte[] {'a', 'b', 'c'}); QValue v = factory.create(in); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 3); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testEmptyBinaryFromInputStream() throws RepositoryException, IOException { InputStream in = new ByteArrayInputStream(new byte[0]); QValue v = factory.create(in); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(0, v.getLength()); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[] {'a', 'b', 'c'}); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 3); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testBinaryFromInputStream() throws RepositoryException, IOException { InputStream in = new ByteArrayInputStream(new byte[] {'a', 'b', 'c'}); QValue v = factory.create(in); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(3, v.getLength()); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testEmptyBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[0]); assertEquals(PropertyType.BINARY, v.getType()); assertValueLength(v, 0); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
public void testBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[] {'a', 'b', 'c'}); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(3, v.getLength()); assertEquals("abc", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("abc", new String(out.toByteArray())); }
public void testEmptyBinaryFromByteArray() throws RepositoryException, IOException { QValue v = factory.create(new byte[0]); assertEquals(PropertyType.BINARY, v.getType()); assertEquals(0, v.getLength()); assertEquals("", v.getString()); ByteArrayOutputStream out = new ByteArrayOutputStream(); spool(out, v.getStream()); assertEquals("", new String(out.toByteArray())); }
/** * * @param paramName * @param value * @param resolver * @throws RepositoryException */ static void addPart(String paramName, QValue value, NamePathResolver resolver, List<FormBodyPart> parts, List<QValue> binaries) throws RepositoryException { FormBodyPartBuilder builder = FormBodyPartBuilder.create().setName(paramName); ContentType ctype = ContentType.create(JcrValueType.contentTypeFromType(value.getType()), DEFAULT_CHARSET); FormBodyPart part; switch (value.getType()) { case PropertyType.BINARY: binaries.add(value); // server detects binaries based on presence of filename parameters (JCR-4154) part = builder.setBody(new InputStreamBody(value.getStream(), ctype, paramName)).build(); break; case PropertyType.NAME: part = builder.setBody(new StringBody(resolver.getJCRName(value.getName()), ctype)).build(); break; case PropertyType.PATH: part = builder.setBody(new StringBody(resolver.getJCRPath(value.getPath()), ctype)).build(); break; default: part = builder.setBody(new StringBody(value.getString(), ctype)).build(); } parts.add(part); }
public void testSetEmptyBinaryValue() throws RepositoryException, IOException { NodeId nid = getNodeId(testPath); Name propName = resolver.getQName("binProp"); Batch b = rs.createBatch(si, nid); b.addProperty(nid, propName, rs.getQValueFactory().create(new byte[0])); rs.submit(b); PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName)); assertFalse(pi.isMultiValued()); InputStream in = pi.getValues()[0].getStream(); assertTrue(in.read() == -1); assertEquals("", pi.getValues()[0].getString()); assertEquals(PropertyType.BINARY, pi.getType()); pi = getPropertyInfo(nid, propName); assertFalse(pi.isMultiValued()); in = pi.getValues()[0].getStream(); assertTrue(in.read() == -1); assertEquals("", pi.getValues()[0].getString()); assertEquals(PropertyType.BINARY, pi.getType()); }