Create data object to send from a file.

@param data Base64 encoded data to upload.
@param type Mime type of the data.
@return Data object to send.
511390
public static Attachment create(@NonNull String data, @NonNull String type, @Nullable String folder, @Nullable String name) {
        return new Attachment(ContentData.create(data, type, name), folder, type);
    }
1058055
public static Serializable fromByteArray( byte[] data )
	{
		try
		{
	        ByteArrayInputStream buf = new ByteArrayInputStream(data);
	        ObjectInputStream objIn = new ObjectInputStream(buf);
	        Serializable response = (Serializable)objIn.readObject();
	        objIn.close();
	        return response;
		}
		catch (Exception e)
		{
			throw new IllegalArgumentException("Cannot deserialize object : "+e.toString());
		}
	}
778816
public function makeFromDataUri($data, $name = null, $mimeType = null)
    {
        if ($data instanceof RawContentInterface) {
            $data = $data->content();
        }

        $resource = @fopen($data, 'r');

        if ( ! $resource) {
            throw new CouldNotReadDataException('Invalid data URI');
        }

        try {
            $meta = stream_get_meta_data($resource);
            // @codeCoverageIgnoreStart
        } catch (Exception $e) {
            throw new CouldNotReadDataException('Failed to interpret Data URI as stream', $e->getCode(), $e);
            // @codeCoverageIgnoreEnd
        }

        if (null === $mimeType) {
            $mimeType = $meta['mediatype'];
        }

        $extension = $this->mimeTypeHelper->guessExtensionForMimeType($mimeType);
        $localPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5($meta['uri']) . '.' . $extension;

        if (null === $name) {
            $name = pathinfo($localPath, PATHINFO_BASENAME);
        }

        try {
            file_put_contents($localPath, stream_get_contents($resource));
            // @codeCoverageIgnoreStart
        } catch (Exception $e) {
            throw new CouldNotReadDataException('Failed to make local file from Data URI', $e->getCode(), $e);
            // @codeCoverageIgnoreEnd
        }

        // Always flag as uploaded, since a temp file was created
        return $this->uploaded()->makeFromLocalPath($localPath, $name);
    }
167741
def FromData(cls, stream, json_data, http, auto_transfer=None,
                 gzip_encoded=False, **kwds):
        """"""
        info = json.loads(json_data)
        missing_keys = cls._REQUIRED_SERIALIZATION_KEYS - set(info.keys())
        if missing_keys:
            raise exceptions.InvalidDataError(
                'Invalid serialization data, missing keys: %s' % (
                    ', '.join(missing_keys)))
        if 'total_size' in kwds:
            raise exceptions.InvalidUserInputError(
                'Cannot override total_size on serialized Upload')
        upload = cls.FromStream(stream, info['mime_type'],
                                total_size=info.get('total_size'),
                                gzip_encoded=gzip_encoded, **kwds)
        if isinstance(stream, io.IOBase) and not stream.seekable():
            raise exceptions.InvalidUserInputError(
                'Cannot restart resumable upload on non-seekable stream')
        if auto_transfer is not None:
            upload.auto_transfer = auto_transfer
        else:
            upload.auto_transfer = info['auto_transfer']
        upload.strategy = RESUMABLE_UPLOAD
        upload._Initialize(  # pylint: disable=protected-access
            http, info['url'])
        upload.RefreshResumableUploadState()
        upload.EnsureInitialized()
        if upload.auto_transfer:
            upload.StreamInChunks()
        return upload
586878
public MessageIDEnvelope sendMessage(Message data) throws ApiException {
        ApiResponse<MessageIDEnvelope> resp = sendMessageWithHttpInfo(data);
        return resp.getData();
    }
758958
private void sendMessage(BeanMessageID type, Buffer payload) {
        Buffer buffer = new Buffer();
        buffer.writeByte((type.getRawValue() >> 8) & 0xff);
        buffer.writeByte(type.getRawValue() & 0xff);
        if (payload != null) {
            try {
                buffer.writeAll(payload);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        GattSerialMessage serialMessage = GattSerialMessage.fromPayload(buffer.readByteArray());
        gattClient.getSerialProfile().sendMessage(serialMessage.getBuffer());
    }
745142
private List<Object> convertType(DataType type, byte[] data)
   {
      List<Object> result = new ArrayList<Object>();
      int index = 0;

      while (index < data.length)
      {
         switch (type)
         {
            case STRING:
            {
               String value = MPPUtility.getUnicodeString(data, index);
               result.add(value);
               index += ((value.length() + 1) * 2);
               break;
            }

            case CURRENCY:
            {
               Double value = Double.valueOf(MPPUtility.getDouble(data, index) / 100);
               result.add(value);
               index += 8;
               break;
            }

            case NUMERIC:
            {
               Double value = Double.valueOf(MPPUtility.getDouble(data, index));
               result.add(value);
               index += 8;
               break;
            }

            case DATE:
            {
               Date value = MPPUtility.getTimestamp(data, index);
               result.add(value);
               index += 4;
               break;

            }

            case DURATION:
            {
               TimeUnit units = MPPUtility.getDurationTimeUnits(MPPUtility.getShort(data, index + 4), m_properties.getDefaultDurationUnits());
               Duration value = MPPUtility.getAdjustedDuration(m_properties, MPPUtility.getInt(data, index), units);
               result.add(value);
               index += 6;
               break;
            }

            case BOOLEAN:
            {
               Boolean value = Boolean.valueOf(MPPUtility.getShort(data, index) == 1);
               result.add(value);
               index += 2;
               break;
            }

            default:
            {
               index = data.length;
               break;
            }
         }
      }

      return result;
   }
290386
public void append(byte[] data) {
        if (data.length >= (this.datas.length - size)) {
            // 扩容
            byte[] newData = new byte[this.datas.length + data.length + this.datas.length / 2];
            System.arraycopy(this.datas, 0, newData, 0, size);
            this.datas = newData;
        }
        System.arraycopy(data, 0, this.datas, size, data.length);
        this.size += data.length;
        modCount++;
    }
1087482
@Override
    InterfaceHttpData getData(HttpRequest request, HttpDataFactory factory) {
        MediaType mediaType = contentType;
        String contentType = mediaType.toString();
        String encoding = mediaType.isTextBased() ? null : "binary";
        Charset charset = mediaType.getCharset().orElse(null);
        FileUpload fileUpload = factory.createFileUpload(request, name, filename, contentType,
            encoding, charset, getLength());
        try {
            setContent(fileUpload);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        return fileUpload;
    }
838184
public void setData(byte[] data, boolean append) {
	lastModified = System.currentTimeMillis();

	// set data
	if (append) {
	    if (this.data != null && data != null) {
		byte[] newData = new byte[this.data.length + data.length];
		int i = 0;
		for (; i < this.data.length; i++) {
		    newData[i] = this.data[i];
		}
		for (; i < this.data.length + data.length; i++) {
		    newData[i] = data[i - this.data.length];
		}
		this.data = newData;
	    }
	    else if (data != null) {
		this.data = data;
	    }
	}
	else {
	    this.data = data;
	}

	// set type
	if (this.data != null) this.type = TYPE_FILE;

    }
611839
public <R> R getData(Class<R> type) {
        return GSON.fromJson(data, type);
    }
1021785
public void fromBytes(byte[] data) {
        if (data == null || data.length != 4) {
            throw new IllegalArgumentException("invalid header data. It can't be null and the length must be 4 byte.");
        }
        this.packetBodyLength = (data[0] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[2] & 0xFF) << 16);
        this.setPacketSequenceNumber(data[3]);
    }
401097
public static <T> T deserializeFromBase64(String data) {
        Objects.requireNonNull(data, Required.DATA.toString());
        
        byte[] bytes = base64Decoder.decode(data);
        return SerializationUtils.deserialize(bytes);
    }
202542
public static byte[] encode(final byte[] data) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        DeflaterOutputStream deflateOut = null;
        try {
            deflateOut = new DeflaterOutputStream(byteOut);
            deflateOut.write(data);
            deflateOut.close();
            byteOut.close();
            return byteOut.toByteArray();
        } finally {
            deflateOut.close();
            byteOut.close();
        }
    }
136377
public static byte[] convert(int data) {
        long len = Integer.toUnsignedLong(data);
        byte[] b = new byte[Datagram.LEN_LIMIT];
        for (int i = 0; i < b.length; i++) {
            b[i] = (byte) (len >> ((b.length - i - 1) * 8));
        }
        return b;
    }
531586
public static ByteBuffer create(CharSequence data, Charset charset) {
		return create(StrUtil.bytes(data, charset));
	}
917101
public static byte[] newByteArray(byte[] data) {
        if (data == null) {
            throw new IllegalArgumentException("Data you want to copy are backed by null object.");
        }
        byte[] buffer = new byte[data.length];
        System.arraycopy(data, 0, buffer, 0, data.length);
        return buffer;
    }