Exemple #1
0
  public static void exportFromDB(GraphDatabaseService graphDatabaseService) {

    GlobalGraphOperations graphOperations = GlobalGraphOperations.at(graphDatabaseService);
    Node refNode = graphDatabaseService.getReferenceNode();
    for (Node node : graphOperations.getAllNodes()) {

      StringBuffer stringBuffer = new StringBuffer();
      stringBuffer.append("{");
      for (String key : node.getPropertyKeys()) {
        String value = (String) node.getProperty(key);
        stringBuffer.append(String.format("%s : %s", key, value));
      }
      for (Relationship rel : node.getRelationships(Direction.OUTGOING)) {}

      stringBuffer.append("}");
    }
  }
  @FixFor("MODE-1308")
  @Test
  public void shouldAllowAnyBinaryImplementation() throws Exception {
    Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured");
    final String stringValue = "This is the string stringValue";
    Binary binaryValue =
        new Binary() {
          public InputStream getStream() throws RepositoryException {
            return new ByteArrayInputStream(stringValue.getBytes());
          }

          public int read(byte[] b, long position) throws IOException, RepositoryException {
            byte[] content = stringValue.getBytes();
            int length =
                b.length + position < content.length ? b.length : (int) (content.length - position);
            System.arraycopy(content, (int) position, b, 0, length);
            return length;
          }

          public long getSize() throws RepositoryException {
            return stringValue.getBytes().length;
          }

          public void dispose() {}
        };
    node.setProperty("binProp", binaryValue);
    Binary nodeValue = node.getProperty("binProp").getBinary();
    assertNotNull(nodeValue);
    assertEquals(stringValue.getBytes().length, nodeValue.getSize());
    byte[] buffer = new byte[100];
    int available;
    InputStream inputStream = nodeValue.getStream();
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    while ((available = inputStream.read(buffer)) != -1) {
      byteOut.write(buffer, 0, available);
    }
    assertArrayEquals(stringValue.getBytes(), byteOut.toByteArray());
  }