Example usage for java.lang Byte valueOf

List of usage examples for java.lang Byte valueOf

Introduction

In this page you can find the example usage for java.lang Byte valueOf.

Prototype

public static Byte valueOf(String s) throws NumberFormatException 

Source Link

Document

Returns a Byte object holding the value given by the specified String .

Usage

From source file:org.geoserver.wps.gs.GeorectifyCoverage.java

@DescribeResults({
        @DescribeResult(name = "result", description = "Georectified raster", type = GridCoverage2D.class),
        @DescribeResult(name = "path", description = "Pathname of the generated raster on the server", type = String.class) })
public Map<String, Object> execute(
        @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage,
        @DescribeParameter(name = "gcp", description = "List of Ground control points.  Points are specified as [x,y] or [x,y,z].") String gcps,
        @DescribeParameter(name = "bbox", description = "Bounding box for output", min = 0) Envelope bbox,
        @DescribeParameter(name = "targetCRS", description = "Coordinate reference system to use for the output raster") CoordinateReferenceSystem crs,
        @DescribeParameter(name = "width", description = "Width of output raster in pixels", min = 0) Integer width,
        @DescribeParameter(name = "height", description = "Height of output raster in pixels", min = 0) Integer height,
        @DescribeParameter(name = "warpOrder", min = 0, description = "Order of the warping polynomial (1 to 3)") Integer warpOrder,
        @DescribeParameter(name = "transparent", min = 0, description = "Force output to have transparent background") Boolean transparent,
        @DescribeParameter(name = "store", min = 0, description = "Indicates whether to keep the output file after processing") Boolean store,
        @DescribeParameter(name = "outputPath", min = 0, description = "Pathname where the output file is stored") String outputPath)
        throws IOException {

    GeoTiffReader reader = null;/* w  w  w  . j  a  va  2s.c om*/
    List<File> removeFiles = new ArrayList<File>();
    String location = null;
    try {
        File tempFolder = config.getTempFolder();
        File loggingFolder = config.getLoggingFolder();

        // do we have to add the alpha channel?
        boolean forceTransparent = false;
        if (transparent == null) {
            transparent = true;
        }
        ColorModel cm = coverage.getRenderedImage().getColorModel();
        if (cm.getTransparency() == Transparency.OPAQUE && transparent) {
            forceTransparent = true;
        }

        // //
        //
        // STEP 1: Getting the dataset to be georectified
        //
        // //
        final Object fileSource = coverage.getProperty(GridCoverage2DReader.FILE_SOURCE_PROPERTY);
        if (fileSource != null && fileSource instanceof String) {
            location = (String) fileSource;
        }
        if (location == null) {
            RenderedImage image = coverage.getRenderedImage();
            if (forceTransparent) {
                ImageWorker iw = new ImageWorker(image);
                iw.forceComponentColorModel();
                final ImageLayout tempLayout = new ImageLayout(image);
                tempLayout.unsetValid(ImageLayout.COLOR_MODEL_MASK).unsetValid(ImageLayout.SAMPLE_MODEL_MASK);
                RenderedImage alpha = ConstantDescriptor.create(Float.valueOf(image.getWidth()),
                        Float.valueOf(image.getHeight()), new Byte[] { Byte.valueOf((byte) 255) },
                        new RenderingHints(JAI.KEY_IMAGE_LAYOUT, tempLayout));
                iw.addBand(alpha, false);
                image = iw.getRenderedImage();
                cm = image.getColorModel();
            }
            File storedImageFile = storeImage(image, tempFolder);
            location = storedImageFile.getAbsolutePath();
            removeFiles.add(storedImageFile);
        }

        // //
        //
        // STEP 2: Adding Ground Control Points
        //
        // //
        final int gcpNum[] = new int[1];
        final String gcp = parseGcps(gcps, gcpNum);
        File vrtFile = addGroundControlPoints(location, gcp, config.getGdalTranslateParameters());
        if (vrtFile == null || !vrtFile.exists() || !vrtFile.canRead()) {
            throw new IOException("Unable to get a valid file with attached Ground Control Points");
        }
        removeFiles.add(vrtFile);

        // //
        //
        // STEP 3: Warping
        //
        // //
        File warpedFile = warpFile(vrtFile, bbox, crs, width, height, warpOrder, tempFolder, loggingFolder,
                config.getExecutionTimeout(), config.getGdalWarpingParameters());
        if (warpedFile == null || !warpedFile.exists() || !warpedFile.canRead()) {
            throw new IOException("Unable to get a valid georectified file");
        }

        boolean expand = false;
        if (cm instanceof IndexColorModel) {
            expand = true;
        } else if (cm instanceof ComponentColorModel && cm.getNumComponents() == 1
                && cm.getComponentSize()[0] == 1) {
            expand = true;
        }
        if (expand) {
            removeFiles.add(warpedFile);
            warpedFile = expandRgba(warpedFile.getAbsolutePath());
        }

        // if we have the output path move the final file there
        if (Boolean.TRUE.equals(store) && outputPath != null) {
            File output = new File(outputPath);
            if (output.exists()) {
                if (!output.delete()) {
                    throw new WPSException("Output file " + outputPath + " exists but cannot be overwritten");
                }
            } else {
                File parent = output.getParentFile();
                if (!parent.exists()) {
                    if (!parent.mkdirs()) {
                        throw new WPSException("Output file parent directory " + parent.getAbsolutePath()
                                + " does not exist and cannot be created");
                    }
                }
            }
            if (!warpedFile.renameTo(output)) {
                throw new WPSException("Could not move " + warpedFile.getAbsolutePath() + " to " + outputPath
                        + ", it's likely a permission issue");
            }
            warpedFile = output;
        }

        // mark the output file for deletion at the end of request
        if (resourceManager != null && !Boolean.TRUE.equals(store)) {
            resourceManager.addResource(new WPSFileResource(warpedFile));
        }

        // //
        //
        // FINAL STEP: Returning the warped gridcoverage
        //
        // //
        reader = new GeoTiffReader(warpedFile);
        GridCoverage2D cov = addLocationProperty(reader.read(null), warpedFile);

        Map<String, Object> result = new HashMap<String, Object>();
        result.put("result", cov);
        result.put("path", warpedFile.getAbsolutePath());
        return result;
    } finally {
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Throwable t) {
                // Does nothing
            }
        }

        for (File file : removeFiles) {
            deleteFile(file);
        }
    }
}

From source file:org.apache.syncope.client.console.wicket.markup.html.form.SpinnerFieldPanel.java

@SuppressWarnings("rawtypes")
@Override/*from   w ww .jav a 2  s  . c o  m*/
public SpinnerFieldPanel<T> setNewModel(final ListItem item) {
    field.setModel(new Model<T>() {

        private static final long serialVersionUID = 6799404673615637845L;

        @Override
        public T getObject() {
            T number = null;

            final Object obj = item.getModelObject();

            if (obj != null && !obj.toString().isEmpty()) {
                if (obj instanceof String) {
                    number = reference.equals(Integer.class) ? reference.cast(Integer.valueOf((String) obj))
                            : reference.equals(Long.class) ? reference.cast(Long.valueOf((String) obj))
                                    : reference.equals(Short.class)
                                            ? reference.cast(Short.valueOf((String) obj))
                                            : reference.equals(Float.class)
                                                    ? reference.cast(Float.valueOf((String) obj))
                                                    : reference.equals(byte.class)
                                                            ? reference.cast(Byte.valueOf((String) obj))
                                                            : reference.cast(Double.valueOf((String) obj));
                } else if (obj instanceof Number) {
                    // Don't parse anything
                    number = reference.cast(obj);
                }
            }

            return number;
        }

        @Override
        @SuppressWarnings("unchecked")
        public void setObject(final T object) {
            item.setModelObject(object == null ? null : object.toString());
        }
    });

    return this;
}

From source file:de.csdev.ebus.command.EBusCommandRegistry.java

/**
 * Checks if the given command method is acceptable for the unescaped telegram
 *
 * @param command/*from w  ww.  j a  v a 2  s  .c o  m*/
 * @param data
 * @return
 */
public boolean matchesCommand(IEBusCommandMethod command, ByteBuffer data) {

    Byte sourceAddress = (Byte) ObjectUtils.defaultIfNull(command.getSourceAddress(),
            Byte.valueOf((byte) 0x00));

    Byte targetAddress = (Byte) ObjectUtils.defaultIfNull(command.getDestinationAddress(),
            Byte.valueOf((byte) 0x00));

    try {

        ByteBuffer masterTelegram = EBusCommandUtils.buildMasterTelegram(command, sourceAddress, targetAddress,
                null);

        ByteBuffer mask = command.getMasterTelegramMask();

        for (int i = 0; i < mask.limit(); i++) {
            byte b = mask.get(i);

            if (b == (byte) 0xFF) {
                if (masterTelegram.get(i) != data.get(i)) {
                    break;
                }
            }
            if (i == mask.limit() - 1) {
                return true;
            }
        }
    } catch (EBusTypeException e) {
        logger.error("error!", e);
    }

    return false;
}

From source file:it.unimi.dsi.util.Properties.java

public void setProperty(final Enum<?> key, final byte b) {
    super.setProperty(key.name().toLowerCase(), Byte.valueOf(b));
}

From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java

/**
 * Reads a <code>byte</code> value from the stream message.
 *
 * @return the next byte from the stream message as a 8-bit
 *         <code>byte</code>
 * @throws JMSException/*  ww w  .  ja  v  a 2s. c  o  m*/
 *             if the JMS provider fails to read the message due to some
 *             internal error.
 * @throws MessageEOFException
 *             if unexpected end of message stream has been reached.
 * @throws MessageFormatException
 *             if this type conversion is invalid.
 * @throws javax.jms.MessageNotReadableException
 *             if the message is in write-only mode.
 */

public byte readByte() throws JMSException {
    initializeReading();
    try {

        this.dataIn.mark(10);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new MessageEOFException("reached end of data");
        }
        if (type == MarshallingSupport.BYTE_TYPE) {
            return this.dataIn.readByte();
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return Byte.valueOf(this.dataIn.readUTF()).byteValue();
        }
        if (type == MarshallingSupport.NULL) {
            this.dataIn.reset();
            throw new NullPointerException("Cannot convert NULL value to byte.");
        } else {
            this.dataIn.reset();
            throw new MessageFormatException(" not a byte type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            JMSException jmsEx = new MessageFormatException(ioe.getMessage());
            jmsEx.setLinkedException(ioe);
            throw jmsEx;
        }
        throw mfe;
    } catch (EOFException e) {
        String exMessage = "Reached premature EOF: " + e.getMessage();
        _log.error(exMessage, e);
        throw new JMSException(exMessage);
    } catch (IOException e) {
        String exMessage = "Could not read boolean: " + e.getMessage();
        _log.error(exMessage, e);
        throw new JMSException(exMessage);
    }
}

From source file:StringUtilities.java

public static Byte[] getByteArray(byte[] bytes) {
    if (bytes == null || bytes.length == 0) {
        return new Byte[0];
    }/*from  w  w w .j  a v  a2 s .  com*/
    Byte[] result = new Byte[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
        result[i] = Byte.valueOf(bytes[i]);
    }

    return result;
}

From source file:com.blockwithme.longdb.test.util.JSONUtil.java

/** Load column. */
private Bytes loadColumn(final JSONObject theColumn, final long theRowId, final int theIndex)
        throws JSONException, UnsupportedEncodingException {

    Bytes returnValue = null;/*from   w  w  w.ja v a  2  s .co  m*/
    final String type = theColumn.getString("type");

    if ("int".equals(type)) {
        final int value = theColumn.getInt("value");
        returnValue = new Bytes(value);
    } else if ("long".equals(type)) {
        final long value = theColumn.getLong("value");
        returnValue = new Bytes(value);
    } else if ("double".equals(type)) {
        final double value = theColumn.getDouble("value");
        returnValue = new Bytes(value);
    } else if ("short".equals(type)) {
        final short value = Short.valueOf(theColumn.getString("value"));
        returnValue = new Bytes(value);
    } else if ("byte".equals(type)) {
        final byte value = Byte.valueOf(theColumn.getString("value"));
        returnValue = new Bytes(value);
    } else if ("String".equals(type)) {
        final String value = theColumn.getString("value");
        returnValue = new Bytes(value.getBytes("UTF-8"));
    } else if (type.contains("blob")) {

        final String sizeStr = type.substring(type.indexOf('(') + 1, type.indexOf(')'));
        final int blobsize = Integer.valueOf(sizeStr);
        final byte[] blobBytes = generateRandomByteArray(blobsize);
        returnValue = new Bytes(blobBytes);
        theColumn.put("type", "convertedBolb");
        theColumn.put("value", "convertedBolb");
        final String mapKey = theColumn.getString("ID") + ':' + theRowId;
        BLOB_MAP.put(mapKey, blobBytes);

    } else if ("convertedBolb".equals(type)) {
        final String mapKey = theColumn.getString("ID") + ":" + theRowId;
        final byte[] blobBytes = BLOB_MAP.get(mapKey);
        returnValue = new Bytes(blobBytes);
    }

    return returnValue;
}

From source file:FormatStorage.Head.java

public void fromJobConf(JobConf job) throws Exception {
    byte var = (byte) job.getInt(ConstVar.HD_var, 0);
    byte compress = (byte) job.getInt(ConstVar.HD_compress, 0);
    byte compressStyle = (byte) job.getInt(ConstVar.HD_compressStyle, 0);
    short primaryIndex = (short) job.getInt(ConstVar.HD_primaryIndex, -1);
    byte encode = (byte) job.getInt(ConstVar.HD_encode, 0);
    byte encodeStyle = (byte) job.getInt(ConstVar.HD_encodeStyle, 0);
    String keyString = job.get(ConstVar.HD_key);
    String[] fieldStrings = job.getStrings(ConstVar.HD_fieldMap);

    LOG.info("in fromJobConf, compressed:" + compress + ",compressStyle:" + compressStyle);

    setVar(var);/*from   w  ww. j  a va 2 s  . co  m*/
    setCompress(compress);
    setCompressStyle(compressStyle);

    setEncode(encode);
    setEncodeStyle(encodeStyle);
    if (keyString != null && keyString.length() != 0) {
        setKey(keyString);
    }

    short fieldNum = 0;
    if (fieldStrings != null) {
        fieldNum = (short) fieldStrings.length;
    }

    FieldMap fieldMap = new FieldMap();
    for (short i = 0; i < fieldNum; i++) {
        String[] def = fieldStrings[i].split(ConstVar.RecordSplit);
        byte type = Byte.valueOf(def[0]);
        int len = Integer.valueOf(def[1]);
        short index = Short.valueOf(def[2]);

        fieldMap.addField(new Field(type, len, index));
    }

    setFieldMap(fieldMap);
    setPrimaryIndex(primaryIndex);
}

From source file:org.omnaest.utils.table.impl.adapter.TableToResultSetAdapter.java

@Override
public byte getByte(String columnLabel) throws SQLException {
    return Byte.valueOf(this.getString(columnLabel));
}