class FileResourceConverter extends ResourceConverterImpl<FileResource, ClientFile> {

    @Override
    protected FileResource resourceSpecificFieldsToServer(ClientFile clientObject, FileResource resultToUpdate, List<Exception> exceptions, ToServerConversionOptions options) throws IllegalParameterValueException {
        if(resultToUpdate.getFileType() != null || resultToUpdate.isReference()){
            String type;
            if (resultToUpdate.isReference()){
                FileResource referenced = (FileResource)repositoryService.getResource(null, resultToUpdate.getReferenceURI());
                type = referenced.getFileType();
            } else {
                type = resultToUpdate.getFileType();
            }

            if (!type.equals(clientObject.getType().name())){
                // it's not allowed to change resource type
                throw new IllegalParameterValueException("type", clientObject.getType().name());
            }
        }

        if (!resultToUpdate.isReference()){
            resultToUpdate.setFileType(clientObject.getType().name());
        }

        if (clientObject.getContent() != null && !"".equals(clientObject.getContent())) {
            try {
                resultToUpdate.setData(DatatypeConverter.parseBase64Binary(clientObject.getContent()));
            } catch (IllegalArgumentException e) {
                throw new IllegalParameterValueException("content", "");
            }
            resultToUpdate.setReferenceURI(null);
            resultToUpdate.setFileType(clientObject.getType().name());
        }
        return resultToUpdate;
    }

}