com.smartdevicelink.proxy.rpc.PutFile Maven / Gradle / Ivy
/*
* Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.smartdevicelink.proxy.rpc;
import androidx.annotation.NonNull;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCRequest;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import java.util.Hashtable;
import java.util.zip.CRC32;
/**
* Used to push a binary data onto the SDL module from a mobile device, such as
* icons and album art.
*
* Parameter List
*
*
*
* Name
* Type
* Description
* Req.
* Notes
* Version Available
*
*
* FileName
* String
* File reference name.
* Y
* Maxlength=500
* SmartDeviceLink 2.0
*
*
* fileType
* FileType
* Selected file type.
* Y
*
* SmartDeviceLink 2.0
*
*
* persistentFile
* Boolean
* Indicates if the file is meant to persist between sessions / ignition cycles. If set to TRUE,then the system will aim to persist this file through session / cycles. While files with this designation will have priority over others,they are subject to deletion by the system at any time.In the event of automatic deletion by the system, the app will receive a rejection and have to resend the file. If omitted, the value will be set to false.
* N
*
* SmartDeviceLink 2.0
*
*
* systemFile
* Boolean
* Indicates if the file is meant to be passed thru core to elsewhere on the system. If set to TRUE, then the system will instead pass the data thru as it arrives to a predetermined area outside of core. If omitted, the value will be set to false.
* N
*
* SmartDeviceLink 2.3.2
*
*
* offset
* Float
* Optional offset in bytes for resuming partial data chunks
* N
* Minvalue=0; Maxvalue=100000000000
* SmartDeviceLink 2.3.2
*
*
* length
* Float
* Optional length in bytes for resuming partial data chunks. If offset is set to 0, then length is the total length of the file to be downloaded
* N
* Minvalue=0; Maxvalue=100000000000
* SmartDeviceLink 2.3.2
*
*
* crc
* Long
* Additional CRC32 checksum to protect data integrity up to 512 Mbits .
* N
* minvalue="0" maxvalue="4294967295"
* SmartDeviceLink 2.3.2
*
*
* Note:
* When using PutFiles you may want to check for memory
*
* Response
* Response is sent, when the file data was copied (success case). Or when an error occurred. Not supported on First generation SDL modules.
*
* Non-default Result Codes:
* SUCCESS
* INVALID_DATA
* OUT_OF_MEMORY
* TOO_MANY_PENDING_REQUESTS
* APPLICATION_NOT_REGISTERED
* GENERIC_ERROR
* REJECTED
*
*
*
* Name
* Type
* Description
* Req.
* Notes
* Version Available
*
*
* spaceAvailable
* Integer
* Provides the total local space available on SDL for the registered app.
*
* Minvalue=0; Maxvalue=2000000000
* SmartDeviceLink 2.0
*
*
*
*
* @see DeleteFile
* @see ListFiles
* @since SmartDeviceLink 2.0
*/
public class PutFile extends RPCRequest {
public static final String KEY_PERSISTENT_FILE = "persistentFile";
public static final String KEY_SYSTEM_FILE = "systemFile";
public static final String KEY_FILE_TYPE = "fileType";
public static final String KEY_SDL_FILE_NAME = "syncFileName";
public static final String KEY_OFFSET = "offset";
public static final String KEY_LENGTH = "length";
public static final String KEY_CRC = "crc";
/**
* Constructs a new PutFile object
*/
public PutFile() {
super(FunctionID.PUT_FILE.toString());
}
/**
* Constructs a new PutFile object indicated by the Hashtable parameter
*
* @param hash The Hashtable to use
*/
public PutFile(Hashtable hash) {
super(hash);
}
/**
* Constructs a new PutFile object
*
* @param syncFileName a String value representing a file reference name
* Notes: Maxlength=500, however the max file name length may vary based on remote filesystem limitations
* @param fileType a FileType value representing a selected file type
*/
public PutFile(@NonNull String syncFileName, @NonNull FileType fileType) {
this();
setSdlFileName(syncFileName);
setFileType(fileType);
}
/**
* Sets a file reference name
*
* @param sdlFileName a String value representing a file reference name
*
* Notes: Maxlength=500, however the max file name length may vary based on remote filesystem limitations
*/
public PutFile setSdlFileName(@NonNull String sdlFileName) {
setParameters(KEY_SDL_FILE_NAME, sdlFileName);
return this;
}
/**
* Gets a file reference name
*
* @return String - a String value representing a file reference name
*/
public String getSdlFileName() {
return getString(KEY_SDL_FILE_NAME);
}
/**
* Sets file type
*
* @param fileType a FileType value representing a selected file type
*/
public PutFile setFileType(@NonNull FileType fileType) {
setParameters(KEY_FILE_TYPE, fileType);
return this;
}
/**
* Gets a file type
*
* @return FileType -a FileType value representing a selected file type
*/
public FileType getFileType() {
return (FileType) getObject(FileType.class, KEY_FILE_TYPE);
}
/**
* Sets a value to indicates if the file is meant to persist between
* sessions / ignition cycles. If set to TRUE, then the system will aim to
* persist this file through session / cycles. While files with this
* designation will have priority over others, they are subject to deletion
* by the system at any time. In the event of automatic deletion by the
* system, the app will receive a rejection and have to resend the file. If
* omitted, the value will be set to false
*
*
* @param persistentFile a Boolean value
*/
public PutFile setPersistentFile(Boolean persistentFile) {
setParameters(KEY_PERSISTENT_FILE, persistentFile);
return this;
}
/**
* Gets a value to Indicates if the file is meant to persist between
* sessions / ignition cycles
*
* @return Boolean -a Boolean value to indicates if the file is meant to
* persist between sessions / ignition cycles
*/
public Boolean getPersistentFile() {
return getBoolean(KEY_PERSISTENT_FILE);
}
public PutFile setFileData(byte[] fileData) {
setBulkData(fileData);
return this;
}
public byte[] getFileData() {
return getBulkData();
}
/**
* @param offset Optional offset in bytes for resuming partial data chunks
* @deprecated as of SmartDeviceLink 4.0. Use {@link #setOffset(Long)} instead.
*/
public PutFile setOffset(Integer offset) {
if (offset == null) {
setOffset((Long) null);
} else {
setOffset(offset.longValue());
}
return this;
}
/**
* @param offset Optional offset in bytes for resuming partial data chunks
*/
public PutFile setOffset(Long offset) {
setParameters(KEY_OFFSET, offset);
return this;
}
public Long getOffset() {
final Object o = getParameters(KEY_OFFSET);
if (o == null) {
return null;
}
if (o instanceof Integer) {
return ((Integer) o).longValue();
} else if (o instanceof Long) {
return (Long) o;
}
return null;
}
/**
* @param length Optional length in bytes for resuming partial data chunks. If offset is set to 0, then length is
* the total length of the file to be downloaded
* @deprecated as of SmartDeviceLink 4.0. Use {@link #setLength(Long)} instead.
*/
public PutFile setLength(Integer length) {
if (length == null) {
setLength((Long) null);
} else {
setLength(length.longValue());
}
return this;
}
/**
* @param length Optional length in bytes for resuming partial data chunks. If offset is set to 0, then length is
* the total length of the file to be downloaded
*/
public PutFile setLength(Long length) {
setParameters(KEY_LENGTH, length);
return this;
}
public Long getLength() {
final Object o = getParameters(KEY_LENGTH);
if (o == null) {
return null;
}
if (o instanceof Integer) {
return ((Integer) o).longValue();
} else if (o instanceof Long) {
return (Long) o;
}
return null;
}
public PutFile setSystemFile(Boolean systemFile) {
setParameters(KEY_SYSTEM_FILE, systemFile);
return this;
}
public Boolean getSystemFile() {
final Object o = getParameters(KEY_SYSTEM_FILE);
if (o instanceof Boolean) {
return (Boolean) o;
} else
return null;
}
/**
* This takes the file data as an array of bytes and calculates the
* CRC32 for it.
*
* @param fileData - the file as a byte array
*/
public PutFile setCRC(byte[] fileData) {
if (fileData != null) {
CRC32 crc = new CRC32();
crc.update(fileData);
parameters.put(KEY_CRC, crc.getValue());
} else {
parameters.remove(KEY_CRC);
}
return this;
}
/**
* This assumes you have created your own CRC32 and are setting it with the file
* Please avoid using your own calculations for this, and use the method
* included in java.util
*
* @param crc - the CRC32 of the file being set
*/
public PutFile setCRC(Long crc) {
if (crc != null) {
parameters.put(KEY_CRC, crc);
} else {
parameters.remove(KEY_CRC);
}
return this;
}
/**
* This returns the CRC, if it has been set, for the file object
*
* @return - a CRC32 Long
*/
public Long getCRC() {
final Object o = parameters.get(KEY_CRC);
if (o == null) {
return null;
}
if (o instanceof Integer) {
return ((Integer) o).longValue();
} else if (o instanceof Long) {
return (Long) o;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy