@Test public void parse() { String header = "form-data; name=\"f\"; filename=\"image-for-upload.jpeg\""; ContentDisposition d = ContentDisposition.parse(header); System.out.format("parsed: %s%n", d); assertEquals("type", "form-data", d.getType()); assertEquals("name", "f", d.getName()); assertEquals("filename", "image-for-upload.jpeg", d.getFilename()); }
public static ContentDisposition parse(String contentDisposition) { List<String> parts = tokenize(contentDisposition); String type = parts.get(0); String name = null; String filename = null; Charset charset = null; Long size = null; ZonedDateTime creationDate = null; ZonedDateTime modificationDate = null; ZonedDateTime readDate = null; for (int i = 1; i < parts.size(); i++) { String part = parts.get(i); int eqIndex = part.indexOf('='); if (eqIndex != -1) { String attribute = part.substring(0, eqIndex); String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1) : part.substring(eqIndex + 1, part.length())); if (attribute.equals("name") ) { name = value; } else if (attribute.equals("filename*") ) { filename = decodeHeaderFieldParam(value); charset = Charset.forName(value.substring(0, value.indexOf('\''))); checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Charset should be UTF-8 or ISO-8859-1"); } else if (attribute.equals("filename") && (filename == null)) { filename = value; } else if (attribute.equals("size") ) { size = Long.parseLong(value); } else if (attribute.equals("creation-date")) { try { creationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("modification-date")) { try { modificationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("read-date")) { try { readDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } } else { throw new IllegalArgumentException("Invalid content disposition format"); } } return new ContentDisposition(type, name, filename, charset, size, creationDate, modificationDate, readDate); }
ContentDisposition { public static ContentDisposition parse(String contentDisposition) { List<String> parts = tokenize(contentDisposition); String type = parts.get(0); String name = null; String filename = null; Charset charset = null; Long size = null; ZonedDateTime creationDate = null; ZonedDateTime modificationDate = null; ZonedDateTime readDate = null; for (int i = 1; i < parts.size(); i++) { String part = parts.get(i); int eqIndex = part.indexOf('='); if (eqIndex != -1) { String attribute = part.substring(0, eqIndex); String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1) : part.substring(eqIndex + 1, part.length())); if (attribute.equals("name") ) { name = value; } else if (attribute.equals("filename*") ) { filename = decodeHeaderFieldParam(value); charset = Charset.forName(value.substring(0, value.indexOf('\''))); checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Charset should be UTF-8 or ISO-8859-1"); } else if (attribute.equals("filename") && (filename == null)) { filename = value; } else if (attribute.equals("size") ) { size = Long.parseLong(value); } else if (attribute.equals("creation-date")) { try { creationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("modification-date")) { try { modificationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("read-date")) { try { readDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } } else { throw new IllegalArgumentException("Invalid content disposition format"); } } return new ContentDisposition(type, name, filename, charset, size, creationDate, modificationDate, readDate); } }
ContentDisposition { public static ContentDisposition parse(String contentDisposition) { List<String> parts = tokenize(contentDisposition); String type = parts.get(0); String name = null; String filename = null; Charset charset = null; Long size = null; ZonedDateTime creationDate = null; ZonedDateTime modificationDate = null; ZonedDateTime readDate = null; for (int i = 1; i < parts.size(); i++) { String part = parts.get(i); int eqIndex = part.indexOf('='); if (eqIndex != -1) { String attribute = part.substring(0, eqIndex); String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1) : part.substring(eqIndex + 1, part.length())); if (attribute.equals("name") ) { name = value; } else if (attribute.equals("filename*") ) { filename = decodeHeaderFieldParam(value); charset = Charset.forName(value.substring(0, value.indexOf('\''))); checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Charset should be UTF-8 or ISO-8859-1"); } else if (attribute.equals("filename") && (filename == null)) { filename = value; } else if (attribute.equals("size") ) { size = Long.parseLong(value); } else if (attribute.equals("creation-date")) { try { creationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("modification-date")) { try { modificationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("read-date")) { try { readDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } } else { throw new IllegalArgumentException("Invalid content disposition format"); } } return new ContentDisposition(type, name, filename, charset, size, creationDate, modificationDate, readDate); } private  ContentDisposition(@Nullable String type, @Nullable String name, @Nullable String filename,
                               @Nullable Charset charset, @Nullable Long size, @Nullable ZonedDateTime creationDate,
                               @Nullable ZonedDateTime modificationDate, @Nullable ZonedDateTime readDate); }
ContentDisposition { public static ContentDisposition parse(String contentDisposition) { List<String> parts = tokenize(contentDisposition); String type = parts.get(0); String name = null; String filename = null; Charset charset = null; Long size = null; ZonedDateTime creationDate = null; ZonedDateTime modificationDate = null; ZonedDateTime readDate = null; for (int i = 1; i < parts.size(); i++) { String part = parts.get(i); int eqIndex = part.indexOf('='); if (eqIndex != -1) { String attribute = part.substring(0, eqIndex); String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1) : part.substring(eqIndex + 1, part.length())); if (attribute.equals("name") ) { name = value; } else if (attribute.equals("filename*") ) { filename = decodeHeaderFieldParam(value); charset = Charset.forName(value.substring(0, value.indexOf('\''))); checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Charset should be UTF-8 or ISO-8859-1"); } else if (attribute.equals("filename") && (filename == null)) { filename = value; } else if (attribute.equals("size") ) { size = Long.parseLong(value); } else if (attribute.equals("creation-date")) { try { creationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("modification-date")) { try { modificationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("read-date")) { try { readDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } } else { throw new IllegalArgumentException("Invalid content disposition format"); } } return new ContentDisposition(type, name, filename, charset, size, creationDate, modificationDate, readDate); } private  ContentDisposition(@Nullable String type, @Nullable String name, @Nullable String filename,
                               @Nullable Charset charset, @Nullable Long size, @Nullable ZonedDateTime creationDate,
                               @Nullable ZonedDateTime modificationDate, @Nullable ZonedDateTime readDate); @Nullable String getType(); @Nullable String getName(); @Nullable String getFilename(); @Nullable Charset getCharset(); @Nullable Long getSize(); @Nullable ZonedDateTime getCreationDate(); @Nullable ZonedDateTime getModificationDate(); @Nullable ZonedDateTime getReadDate(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); static Builder builder(String type); static ContentDisposition empty(); static ContentDisposition parse(String contentDisposition); }
ContentDisposition { public static ContentDisposition parse(String contentDisposition) { List<String> parts = tokenize(contentDisposition); String type = parts.get(0); String name = null; String filename = null; Charset charset = null; Long size = null; ZonedDateTime creationDate = null; ZonedDateTime modificationDate = null; ZonedDateTime readDate = null; for (int i = 1; i < parts.size(); i++) { String part = parts.get(i); int eqIndex = part.indexOf('='); if (eqIndex != -1) { String attribute = part.substring(0, eqIndex); String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1) : part.substring(eqIndex + 1, part.length())); if (attribute.equals("name") ) { name = value; } else if (attribute.equals("filename*") ) { filename = decodeHeaderFieldParam(value); charset = Charset.forName(value.substring(0, value.indexOf('\''))); checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Charset should be UTF-8 or ISO-8859-1"); } else if (attribute.equals("filename") && (filename == null)) { filename = value; } else if (attribute.equals("size") ) { size = Long.parseLong(value); } else if (attribute.equals("creation-date")) { try { creationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("modification-date")) { try { modificationDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } else if (attribute.equals("read-date")) { try { readDate = ZonedDateTime.parse(value, RFC_1123_DATE_TIME); } catch (DateTimeParseException ex) { } } } else { throw new IllegalArgumentException("Invalid content disposition format"); } } return new ContentDisposition(type, name, filename, charset, size, creationDate, modificationDate, readDate); } private  ContentDisposition(@Nullable String type, @Nullable String name, @Nullable String filename,
                               @Nullable Charset charset, @Nullable Long size, @Nullable ZonedDateTime creationDate,
                               @Nullable ZonedDateTime modificationDate, @Nullable ZonedDateTime readDate); @Nullable String getType(); @Nullable String getName(); @Nullable String getFilename(); @Nullable Charset getCharset(); @Nullable Long getSize(); @Nullable ZonedDateTime getCreationDate(); @Nullable ZonedDateTime getModificationDate(); @Nullable ZonedDateTime getReadDate(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); static Builder builder(String type); static ContentDisposition empty(); static ContentDisposition parse(String contentDisposition);  }