Package org.apache.isis.applib.value

Examples of org.apache.isis.applib.value.Blob


    @Test
    public void testEncode_and_decode() {
        String encoded = value.toEncodedString(blob);
        assertEquals("myfile1.docx:application/vnd.ms-word:AQIDBA==", encoded);
        Blob decoded = value.fromEncodedString(encoded);
        assertThat(decoded.getName(), is("myfile1.docx"));
        assertThat(decoded.getMimeType().getPrimaryType(), is("application"));
        assertThat(decoded.getMimeType().getSubType(), is("vnd.ms-word"));
        assertThat(decoded.getBytes().length, is(4));
    }
View Full Code Here


        throw new IndexOutOfBoundsException();
    }

    public void setObject(ExecutionContext ec, PreparedStatement preparedStmt, int[] exprIndex, Object value)
    {
        Blob blob = ((Blob)value);
        if (blob == null) {
            getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], null);
            getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], null);

            // using:
            // getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], null);
            // fails for PostgreSQL, as interprets as a reference to an oid (pointer to offline blob)
            // rather than a bytea (inline blob)
            try {
                preparedStmt.setBytes(exprIndex[2], null);
            } catch (SQLException e) {
                // ignore
            }
        } else {
            getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], blob.getName());
            getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], blob.getMimeType().getBaseType());
            getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], blob.getBytes());
        }
    }
View Full Code Here

        final String mimeTypeBase = getDatastoreMapping(1).getString(resultSet, exprIndex[1]);
        final byte[] bytes = (byte[]) getDatastoreMapping(2).getObject(resultSet, exprIndex[2]);
        if(name == null || mimeTypeBase == null || bytes == null) {
            return null;
        }
        return new Blob(name, mimeTypeBase, bytes);
    }
View Full Code Here

        addColumns(ClassNameConstants.BYTE_ARRAY); // bytes
    }

    public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value)
    {
        Blob blob = ((Blob)value);
        switch (index) {
            case 0: return blob.getName();
            case 1: return blob.getMimeType().getBaseType();
            case 2: return blob.getBytes();
        }
        throw new IndexOutOfBoundsException();
    }
View Full Code Here

            @Test
            public void happyCase() throws Exception {

                byte[] bytes = "{\"foo\": \"bar\"}".getBytes(Charset.forName("UTF-8"));
                final Blob newAttachment = new Blob("myfile.json", new MimeType("application/json"), bytes);

                // when
                toDoItem.setAttachment(newAttachment);

                // then
View Full Code Here

    // EncoderDecoder
    // //////////////////////////////////////////////////////////////////

    @Override
    protected String doEncode(final Object object) {
        Blob blob = (Blob)object;
        return blob.getName() + ":" + blob.getMimeType().getBaseType() + ":" + Base64.encodeBase64String((blob.getBytes()));
    }
View Full Code Here

        final String name  = data.substring(0, colonIdx);
        final int colon2Idx  = data.indexOf(":", colonIdx+1);
        final String mimeTypeBase = data.substring(colonIdx+1, colon2Idx);
        final byte[] bytes = Base64.decodeBase64(data.substring(colon2Idx+1));
        try {
            return new Blob(name, new MimeType(mimeTypeBase), bytes);
        } catch (MimeTypeParseException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

        final Object object = adapter.getObject();
        if(!(object instanceof Blob)) {
            return null;
        }
       
        final Blob blob = (Blob)object;
        final MimeType mimeType = blob.getMimeType();
        if(mimeType == null || !mimeType.getPrimaryType().equals("image")) {
            return null;
        }
       
        final BufferedImage image = asBufferedImage(blob);
View Full Code Here

        if(value instanceof Clob) {
            Clob clob = (Clob)value;
            return handlerFor(resourceStreamFor(clob), clob);
        }
        if(value instanceof Blob) {
            Blob blob = (Blob)value;
            return handlerFor(resourceStreamFor(blob), blob);
        }
        return null;
    }
View Full Code Here

        if(value instanceof Clob) {
            Clob clob = (Clob)value;
            return handlerFor(resourceStreamFor(clob), clob);
        }
        if(value instanceof Blob) {
            Blob blob = (Blob)value;
            return handlerFor(resourceStreamFor(blob), blob);
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.applib.value.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.