All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.parse.ParseFileHttpBody Maven / Gradle / Ivy

Go to download

A library that gives you access to the powerful Parse cloud platform from your Android app.

There is a newer version: 1.17.3
Show newest version
/*
 * Copyright (c) 2015-present, Parse, LLC.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
package com.parse;

import com.parse.http.ParseHttpBody;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/** package */ class ParseFileHttpBody extends ParseHttpBody {

  /* package */ final File file;

  public ParseFileHttpBody(File file) {
    this(file, null);
  }

  public ParseFileHttpBody(File file, String contentType) {
    super(contentType, file.length());
    this.file = file;
  }

  @Override
  public InputStream getContent() throws IOException {
    return new FileInputStream(file);
  }

  @Override
  public void writeTo(OutputStream out) throws IOException {
    if (out == null) {
      throw new IllegalArgumentException("Output stream can not be null");
    }

    final FileInputStream fileInput = new FileInputStream(file);
    try {
      ParseIOUtils.copy(fileInput, out);
    } finally {
      ParseIOUtils.closeQuietly(fileInput);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy