⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valuehelper.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @throws IllegalStateException     * @deprecated Use {@link #copy(Value[], ValueFactory)} instead.     */    public static Value[] copy(Value[] srcValues) throws IllegalStateException {        return copy(srcValues, ValueFactoryImpl.getInstance());    }    /**     * @param srcValues     * @param factory     * @throws IllegalStateException     */    public static Value[] copy(Value[] srcValues, ValueFactory factory)        throws IllegalStateException {        if (srcValues == null) {            return null;        }        Value[] newValues = new Value[srcValues.length];        for (int i = 0; i < srcValues.length; i++) {            newValues[i] = copy(srcValues[i], factory);        }        return newValues;    }    /**     * Serializes the given value to a <code>String</code>. The serialization     * format is the same as used by Document & System View XML, i.e.     * binary values will be Base64-encoded whereas for all others     * <code>{@link Value#getString()}</code> will be used.     *     * @param value        the value to be serialized     * @param encodeBlanks if <code>true</code> space characters will be encoded     *                     as <code>"_x0020_"</code> within he output string.     * @return a string representation of the given value.     * @throws IllegalStateException if the given value is in an illegal state     * @throws RepositoryException   if an error occured during the serialization.     */    public static String serialize(Value value, boolean encodeBlanks)            throws IllegalStateException, RepositoryException {        StringWriter writer = new StringWriter();        try {            serialize(value, encodeBlanks, writer);        } catch (IOException ioe) {            throw new RepositoryException("failed to serialize value",                    ioe);        }        return writer.toString();    }    /**     * Outputs the serialized value to a <code>Writer</code>. The serialization     * format is the same as used by Document & System View XML, i.e.     * binary values will be Base64-encoded whereas for all others     * <code>{@link Value#getString()}</code> will be used for serialization.     *     * @param value        the value to be serialized     * @param encodeBlanks if <code>true</code> space characters will be encoded     *                     as <code>"_x0020_"</code> within he output string.     * @param writer       writer to output the encoded data     * @throws IllegalStateException if the given value is in an illegal state     * @throws IOException           if an i/o error occured during the     *                               serialization     * @throws RepositoryException   if an error occured during the serialization.     */    public static void serialize(Value value, boolean encodeBlanks,                                 Writer writer)            throws IllegalStateException, IOException, RepositoryException {        if (value.getType() == PropertyType.BINARY) {            // binary data, base64 encoding required;            // the encodeBlanks flag can be ignored since base64-encoded            // data cannot contain space characters            InputStream in = value.getStream();            try {                Base64.encode(in, writer);                // no need to close StringWriter                //writer.close();            } finally {                try {                    in.close();                } catch (IOException e) {                    // ignore                }            }        } else {            String textVal = value.getString();            if (encodeBlanks) {                // enocde blanks in string                textVal = Text.replace(textVal, " ", "_x0020_");            }            writer.write(textVal);        }    }    /**     * Deserializes the given string to a <code>Value</code> of the given type.     * Same as {@link #deserialize(String, int, boolean, ValueFactory)} using     * <code>ValueFactoryImpl</code>.     *     * @param value        string to be deserialized     * @param type         type of value     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>     *                     character sequences will be decoded to single space     *                     characters each.     * @return the deserialized <code>Value</code>     * @throws ValueFormatException if the string data is not of the required     *                              format     * @throws RepositoryException  if an error occured during the     *                              deserialization.     * @deprecated Use {@link #deserialize(String, int, boolean, ValueFactory)}     * instead.     */    public static Value deserialize(String value, int type,                                    boolean decodeBlanks)            throws ValueFormatException, RepositoryException {        return deserialize(value, type, decodeBlanks, ValueFactoryImpl.getInstance());    }    /**     * Deserializes the given string to a <code>Value</code> of the given type.     *     * @param value        string to be deserialized     * @param type         type of value     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>     *                     character sequences will be decoded to single space     *                     characters each.     * @param factory      ValueFactory used to build the <code>Value</code> object.     * @return the deserialized <code>Value</code>     * @throws ValueFormatException if the string data is not of the required     *                              format     * @throws RepositoryException  if an error occured during the     *                              deserialization.     */    public static Value deserialize(String value, int type, boolean decodeBlanks,                                    ValueFactory factory)            throws ValueFormatException, RepositoryException {        if (type == PropertyType.BINARY) {            // base64 encoded binary value;            // the encodeBlanks flag can be ignored since base64-encoded            // data cannot contain encoded space characters            ByteArrayOutputStream baos = new ByteArrayOutputStream();            try {                Base64.decode(value, baos);                // no need to close ByteArrayOutputStream                //baos.close();            } catch (IOException ioe) {                throw new RepositoryException("failed to decode binary value",                        ioe);            }            // NOTE: for performance reasons the BinaryValue is created directly            // from the byte-array. This is inconsistent with the other calls,            // that delegate the value creation to the ValueFactory.            return new BinaryValue(baos.toByteArray());        } else {            if (decodeBlanks) {                // decode encoded blanks in value                value = Text.replace(value, "_x0020_", " ");            }            return convert(value, type, factory);        }    }    /**     * Deserializes the string data read from the given reader to a     * <code>Value</code> of the given type. Same as     * {@link #deserialize(Reader, int, boolean, ValueFactory)} using     * <code>ValueFactoryImpl</code>.     *     * @param reader       reader for the string data to be deserialized     * @param type         type of value     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>     *                     character sequences will be decoded to single space     *                     characters each.     * @return the deserialized <code>Value</code>     * @throws IOException          if an i/o error occured during the     *                              serialization     * @throws ValueFormatException if the string data is not of the required     *                              format     * @throws RepositoryException  if an error occured during the     *                              deserialization.     * @deprecated Use {@link #deserialize(Reader, int, boolean, ValueFactory)}     * instead.     */    public static Value deserialize(Reader reader, int type,                                    boolean decodeBlanks)            throws IOException, ValueFormatException, RepositoryException {        return deserialize(reader, type, decodeBlanks, ValueFactoryImpl.getInstance());    }    /**     * Deserializes the string data read from the given reader to a     * <code>Value</code> of the given type.     *     * @param reader       reader for the string data to be deserialized     * @param type         type of value     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>     *                     character sequences will be decoded to single space     *                     characters each.     * @param factory      ValueFactory used to build the <code>Value</code> object.     * @return the deserialized <code>Value</code>     * @throws IOException          if an i/o error occured during the     *                              serialization     * @throws ValueFormatException if the string data is not of the required     *                              format     * @throws RepositoryException  if an error occured during the     *                              deserialization.     */    public static Value deserialize(Reader reader, int type,                                    boolean decodeBlanks, ValueFactory factory)            throws IOException, ValueFormatException, RepositoryException {        if (type == PropertyType.BINARY) {            // base64 encoded binary value;            // the encodeBlanks flag can be ignored since base64-encoded            // data cannot contain encoded space characters            // decode to temp file            TransientFileFactory fileFactory = TransientFileFactory.getInstance();            final File tmpFile = fileFactory.createTransientFile("bin", null, null);            FileOutputStream out = new FileOutputStream(tmpFile);            try {                Base64.decode(reader, out);            } finally {                out.close();            }            // create an InputStream that keeps a hard reference to the temp file            // in order to prevent its automatic deletion once the associated            // File object is reclaimed by the garbage collector;            // pass InputStream wrapper to ValueFactory, that creates a BinaryValue.            return factory.createValue(new FilterInputStream(new FileInputStream(tmpFile)) {                public void close() throws IOException {                    in.close();                    // temp file can now safely be removed                    tmpFile.delete();                }            });/*            ByteArrayOutputStream baos = new ByteArrayOutputStream();            Base64.decode(reader, baos);            // no need to close ByteArrayOutputStream            //baos.close();            return new BinaryValue(baos.toByteArray());*/        } else {            char[] chunk = new char[8192];            int read;            StringBuffer buf = new StringBuffer();            while ((read = reader.read(chunk)) > -1) {                buf.append(chunk, 0, read);            }            String value = buf.toString();            if (decodeBlanks) {                // decode encoded blanks in value                value = Text.replace(value, "_x0020_", " ");            }            return convert(value, type, factory);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -