Creates a non-binary media type with the given type, subtype, and UTF-8 encoding
@throws com.tngtech.jgiven.exception.JGivenWrongUsageException if any of the given arguments is {@code null}
779587
public static MediaType nonBinaryUtf8( MediaType.Type type, String subType ) {
        return new MediaType( type, subType, UTF_8 );
    }
1307654
@Override
    public String format( Date date, String... args ) {
        if( date == null ) {
            return "";
        }

        if( args.length == 0 ) {
            throw new JGivenWrongUsageException( String.format( "A SimpleDateFormat pattern is expected as first argument" ) );
        }

        String pattern = args[0];
        Locale locale = Locale.getDefault();
        if( args.length > 1 ) {
            locale = new Locale( args[1] );
        }

        SimpleDateFormat sdf;
        try {
            sdf = new SimpleDateFormat( pattern, locale );
        } catch( IllegalArgumentException e ) {
            throw new JGivenWrongUsageException( String.format( "A valid SimpleDateFormat pattern is expected (was '%s')", pattern ) );
        }

        return sdf.format( date );
    }
307561
private JsonEncoding getJsonEncoding(MediaType contentType) {
		if (contentType != null && contentType.getCharset() != null) {
			Charset charset = contentType.getCharset();
			for (JsonEncoding encoding : JsonEncoding.values()) {
				if (charset.name().equals(encoding.getJavaName())) {
					return encoding;
				}
			}
		}
		return JsonEncoding.UTF8;
	}
426721
@Override
	public Object convertJsonToJava(String jsonArg, Type paramType, Annotation[] parameterAnnotations) throws JsonUnmarshallingException, JsonMarshallerException {
		if ("null".equals(jsonArg)) {
			return null;
		}
		JsonUnmarshaller juma = getJsonUnmarshallerAnnotation(parameterAnnotations);
		if (null != juma) {
			Object result = getResult(jsonArg, argumentServices.getIJsonMarshallerInstance(juma.value()), juma.type());
			argumentServices.checkType(result, paramType);
			return result;
		} else {
			return convertArgument(jsonArg, paramType);
		}
	}
1238686
def generate_content_media_type(self):
        
        if self._definition['contentMediaType'] == 'application/json':
            with self.l('if isinstance({variable}, bytes):'):
                with self.l('try:'):
                    self.l('{variable} = {variable}.decode("utf-8")')
                with self.l('except Exception:'):
                    self.l('raise JsonSchemaException("{name} must encoded by utf8")')
            with self.l('if isinstance({variable}, str):'):
                with self.l('try:'):
                    self.l('import json')
                    self.l('{variable} = json.loads({variable})')
                with self.l('except Exception:'):
                    self.l('raise JsonSchemaException("{name} must be valid JSON")')
405723
public void writeStringNoTag(final String value) throws IOException {
    // Unfortunately there does not appear to be any way to tell Java to encode
    // UTF-8 directly into our buffer, so we have to let it create its own byte
    // array and then copy.
    final byte[] bytes = value.getBytes("UTF-8");
    writeRawVarint32(bytes.length);
    writeRawBytes(bytes);
  }
79687
@Override
    public void setDefaultMediaType(String mediaType) {
        if (mediaType != null) {
            int i = mediaType.indexOf('/');
            if (i == -1 || i != mediaType.lastIndexOf('/'))
                throw new IllegalArgumentException("Media-type must follow the pattern {type}/{subtype}");
        }
        this.defaultMediaType = mediaType;
    }
1056280
public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }
469618
public static MediaType parseMediaType(String mediaType) {
        MimeType type;
        try {
            type = MimeTypeUtils.parseMimeType(mediaType);
        } catch (InvalidMimeTypeException ex) {
            throw new InvalidMediaTypeException(ex);
        }
        try {
            return new MediaType(type.getType(), type.getSubtype(), type.getParameters());
        } catch (IllegalArgumentException ex) {
            throw new InvalidMediaTypeException(mediaType, ex.getMessage());
        }
    }
106807
@SuppressWarnings("unchecked")
    @NotNull
    public <TYPE> TYPE create(@NotNull final String xml, @NotNull final JAXBContext jaxbContext) throws UnmarshalObjectException {

        Contract.requireArgNotNull("xml", xml);
        Contract.requireArgNotNull("jaxbContext", jaxbContext);

        return (TYPE) create(new StringReader(xml), jaxbContext);

    }
533292
public byte[] toJsonBytes(final Object resource) throws UnsupportedEncodingException {
        if (resource instanceof JSONObject) {
            final JSONObject json = (JSONObject) resource;
            return json.toString().getBytes("UTF-8");
        }

        final HashMap<String, Object> out = new HashMap<String, Object>();
        final JSONObject res = beanSerialize(resource, out);
        if (res == null || res.length() == 0) {
            return new JSONObject(out).toString().getBytes("UTF-8");
        } else {
            return res.toString().getBytes("UTF-8");
        }
    }
876728
public static Attachment fromBase64( String base64encodedContent, MediaType mediaType ) {
        if( !mediaType.isBinary() ) {
            throw new IllegalArgumentException( "MediaType must be binary" );
        }
        return new Attachment( base64encodedContent, mediaType );
    }
608081
public static MediaType text( String subType, Charset charset ) {
        return nonBinary( TEXT, subType, charset );
    }
425718
public static synchronized MediaType create(String type, String... fileExtensisons) {
		return create(type, NO_ATTR, fileExtensisons);
	}
492628
public MimeType getMimeType() {
		if (format >= 0 && format < MIME_TYPE_STRINGS.length) {
			if (format == FORMAT_JPEG && progressive)
			{
				return new MimeType("image/pjpeg");
			}
			return new MimeType(MIME_TYPE_STRINGS[format]);
		} else {
			return null;
		}
	}
678141
protected boolean isJsonType(MediaType mediaType) {
        /*
         * As suggested by Stephen D, there are 2 ways to check: either being as inclusive as possible (if subtype is "json"), or exclusive
         * (major type "application", minor type "json"). Let's start with inclusive one, hard to know which major types we should cover
         * aside from "application".
         */
        if (mediaType != null) {
            // Ok: there are also "xxx+json" subtypes, which count as well
            String subtype = mediaType.getSubtype();
            return "json".equalsIgnoreCase(subtype) || subtype.endsWith("+json");
        }
        /*
         * Not sure if this can happen; but it seems reasonable that we can at least produce json without media type?
         */
        return true;
    }
718563
public static MediaType valueOf(String type) throws IllegalArgumentException {
        if (type == null || type.trim().isEmpty() || type.startsWith(SUBTYPE_SEPARATOR) || type.endsWith(SUBTYPE_SEPARATOR)) {
            throw new IllegalArgumentException("Invalid mime type '" + type + "'");
        }
        String[] splitType = type.split(SUBTYPE_SEPARATOR);
        if (splitType.length == 2) {
            nonEmpty(type, splitType[0]);
            nonEmpty(type, splitType[1]);
            Map<String, String> parameters = new HashMap<>();
            String subType = splitType[1];
            if (splitType[1].contains(PARAMETERS_SEPARATOR)) {
                String[] subTypeWithparameter = splitType[1].split(PARAMETERS_SEPARATOR);
                String paramString = subTypeWithparameter[1].trim();
                subType = subTypeWithparameter[0];
                parameters = parseParameters(paramString);
            }
            return new MediaType(splitType[0].trim(), subType.trim(), parameters);
        }
        if (!type.contains(SUBTYPE_SEPARATOR)) {
            String mimeType = mimeMappings.getMimeType(type);
            if (mimeType != null) {
                return valueOf(mimeType);
            }
        }
        throw new IllegalArgumentException("Invalid mime type '" + type + "'");
    }