Skip to content

Instantly share code, notes, and snippets.

@jottley
Created July 16, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jottley/904d754d49201db99b9a863fe6f9c150 to your computer and use it in GitHub Desktop.
Save jottley/904d754d49201db99b9a863fe6f9c150 to your computer and use it in GitHub Desktop.
Dropbox PUT File
/**
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Alfresco is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @author Jared Ottley <jared.ottley@alfresco.com>
*/
// 300 MB
protected final long MAX_FILE_SIZE = 314572800L;
public Metadata putFile(String path, ContentReader reader)
throws FileSizeException, RuntimeException
{
Metadata metadata = null;
try
{
if (reader.getSize() < MAX_FILE_SIZE)
{
byte[] file = getBytes(reader);
metadata = super.putFile(path, file);
}
else
{
throw new FileSizeException();
}
}
catch (Exception e)
{
throw new RuntimeException(e);
}
return metadata;
}
private byte[] getBytes(ContentReader reader)
throws IOException
{
byte[] ret = newbyte[(int)reader.getSize()];
for (int i = 0; i < reader.getSize(); i++)
{
ret[i] = (byte)reader.getContentInputStream().read();
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment