Tabnine Logo
jodd.http.up
Code IndexAdd Tabnine to your IDE (free)

How to use jodd.http.up

Best Java code snippets using jodd.http.up (Showing top 14 results out of 315)

origin: oblac/jodd

/**
 * Appends {@link jodd.http.up.Uploadable} to buffer.
 */
public Buffer append(final Uploadable uploadable) {
  list.add(uploadable);
  size += uploadable.getSize();
  last = null;
  return this;
}
origin: oblac/jodd

/**
 * Wraps non-Strings form values with {@link jodd.http.up.Uploadable uploadable content}.
 * Detects invalid types and throws an exception. So all uploadable values
 * are of the same type.
 */
protected Object wrapFormValue(final Object value) {
  if (value == null) {
    return null;
  }
  if (value instanceof CharSequence) {
    return value.toString();
  }
  if (value instanceof Number) {
    return value.toString();
  }
  if (value instanceof Boolean) {
    return value.toString();
  }
  if (value instanceof File) {
    return new FileUploadable((File) value);
  }
  if (value instanceof byte[]) {
    return new ByteArrayUploadable((byte[]) value, null);
  }
  if (value instanceof Uploadable) {
    return value;
  }
  throw new HttpException("Unsupported value type: " + value.getClass().getName());
}
origin: oblac/jodd

/**
 * Writes content to the writer.
 */
public void writeTo(final Writer writer) throws IOException {
  for (Object o : list) {
    if (o instanceof FastByteBuffer) {
      FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
      byte[] array = fastByteBuffer.toArray();
      writer.write(new String(array, StringPool.ISO_8859_1));
    }
    else if (o instanceof Uploadable) {
      Uploadable uploadable = (Uploadable) o;
      InputStream inputStream = uploadable.openInputStream();
      try {
        StreamUtil.copy(inputStream, writer, StringPool.ISO_8859_1);
      }
      finally {
        StreamUtil.close(inputStream);
      }
    }
  }
}
origin: oblac/jodd

Uploadable uploadable = (Uploadable) o;
InputStream inputStream = uploadable.openInputStream();
int remaining = uploadable.getSize();
origin: oblac/jodd

Uploadable uploadable = (Uploadable) value;
String fileName = uploadable.getFileName();
if (fileName == null) {
  fileName = name;
buffer.append("\"; filename=\"").append(fileName).append('"').append(CRLF);
String mimeType = uploadable.getMimeType();
if (mimeType == null) {
  mimeType = MimeTypes.getMimeType(FileNameUtil.getExtension(fileName));
origin: oblac/jodd

@Test
void testUploadWithUploadable() throws IOException {
  HttpResponse response = HttpRequest
      .post("http://localhost:8173/echo2")
      .multipart(true)
      .form("id", "12")
      .form("file", new ByteArrayUploadable(
        "upload тест".getBytes(StringPool.UTF_8), "d ст", MimeTypes.MIME_TEXT_PLAIN))
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("12", Data.ref.params.get("id"));
  assertEquals("upload тест", Data.ref.parts.get("file"));
  assertEquals("d ст", Data.ref.fileNames.get("file"));
}
origin: org.jodd/jodd-http

/**
 * Wraps non-Strings form values with {@link jodd.http.up.Uploadable uploadable content}.
 * Detects invalid types and throws an exception. So all uploadable values
 * are of the same type.
 */
protected Object wrapFormValue(final Object value) {
  if (value == null) {
    return null;
  }
  if (value instanceof CharSequence) {
    return value.toString();
  }
  if (value instanceof Number) {
    return value.toString();
  }
  if (value instanceof Boolean) {
    return value.toString();
  }
  if (value instanceof File) {
    return new FileUploadable((File) value);
  }
  if (value instanceof byte[]) {
    return new ByteArrayUploadable((byte[]) value, null);
  }
  if (value instanceof Uploadable) {
    return value;
  }
  throw new HttpException("Unsupported value type: " + value.getClass().getName());
}
origin: org.jodd/jodd-http

Uploadable uploadable = (Uploadable) o;
InputStream inputStream = uploadable.openInputStream();
int remaining = uploadable.getSize();
origin: org.jodd/jodd-http

Uploadable uploadable = (Uploadable) value;
String fileName = uploadable.getFileName();
if (fileName == null) {
  fileName = name;
buffer.append("\"; filename=\"").append(fileName).append('"').append(CRLF);
String mimeType = uploadable.getMimeType();
if (mimeType == null) {
  mimeType = MimeTypes.getMimeType(FileNameUtil.getExtension(fileName));
origin: oblac/jodd

@Test
void testUploadWithUploadable() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  HttpResponse response = HttpRequest
      .post("http://localhost:8081/hello")
      .multipart(true)
      .form("id", "12")
      .form("file", new ByteArrayUploadable(
        "upload тест".getBytes(StringPool.UTF_8), "d ст", MimeTypes.MIME_TEXT_PLAIN))
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("POST", echoTestServer.method);
  assertEquals("12", echoTestServer.params.get("id"));
  File uploadedFile = new File(echoTestServer.files.get("file").toString());
  assertNotNull(uploadedFile);
  assertEquals("upload тест", FileUtil.readString(uploadedFile));
  assertEquals("POST /hello", response.body());
  echoTestServer.stop();
}
origin: oblac/jodd

/**
 * Writes content to the output stream.
 */
public void writeTo(final OutputStream out) throws IOException {
  for (Object o : list) {
    if (o instanceof FastByteBuffer) {
      FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
      out.write(fastByteBuffer.toArray());
    }
    else if (o instanceof Uploadable) {
      Uploadable uploadable = (Uploadable) o;
      InputStream inputStream = uploadable.openInputStream();
      try {
        StreamUtil.copy(inputStream, out);
      }
      finally {
        StreamUtil.close(inputStream);
      }
    }
  }
}
origin: org.jodd/jodd-http

/**
 * Appends {@link jodd.http.up.Uploadable} to buffer.
 */
public Buffer append(final Uploadable uploadable) {
  list.add(uploadable);
  size += uploadable.getSize();
  last = null;
  return this;
}
origin: org.jodd/jodd-http

/**
 * Writes content to the output stream.
 */
public void writeTo(final OutputStream out) throws IOException {
  for (Object o : list) {
    if (o instanceof FastByteBuffer) {
      FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
      out.write(fastByteBuffer.toArray());
    }
    else if (o instanceof Uploadable) {
      Uploadable uploadable = (Uploadable) o;
      InputStream inputStream = uploadable.openInputStream();
      try {
        StreamUtil.copy(inputStream, out);
      }
      finally {
        StreamUtil.close(inputStream);
      }
    }
  }
}
origin: org.jodd/jodd-http

/**
 * Writes content to the writer.
 */
public void writeTo(final Writer writer) throws IOException {
  for (Object o : list) {
    if (o instanceof FastByteBuffer) {
      FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
      byte[] array = fastByteBuffer.toArray();
      writer.write(new String(array, StringPool.ISO_8859_1));
    }
    else if (o instanceof Uploadable) {
      Uploadable uploadable = (Uploadable) o;
      InputStream inputStream = uploadable.openInputStream();
      try {
        StreamUtil.copy(inputStream, writer, StringPool.ISO_8859_1);
      }
      finally {
        StreamUtil.close(inputStream);
      }
    }
  }
}
jodd.http.up

Most used classes

  • ByteArrayUploadable
    Uploadable wrapper of byte array.
  • FileUploadable
    File uploadable.
  • Uploadable
    Common interface of uploaded content for jodd.http.HttpBase#form(). All supported objects that can b
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now