/** * Checks if a stream has more bytes. If the provided stream is not * markable, it wrappes a {@link BufferedInputStream} around the stream and * returns it. * * @param stream * the stream * @param bufferSize * the size of the buffer in bytes if a * {@link BufferedInputStream} has to be created * @return {@code null} if the stream doesn't have more bytes, the provided * stream if the provided stream is markable and has more bytes, or * a {@link BufferedInputStream} if the provided stream is not * markable and has more bytes * * @throws IOException */ public static InputStream checkForBytes(InputStream stream, int bufferSize) throws IOException { if (stream == null) { return null; } InputStream checkStream = stream; if (!stream.markSupported()) { checkStream = new BufferedInputStream(stream, bufferSize); } if (checkForBytes(checkStream)) { return checkStream; } return null; }
/** * Checks if a stream has more bytes. If the provided stream is not * markable, it wrappes a {@link BufferedInputStream} around the stream and * returns it. * * @param stream * the stream * @param bufferSize * the size of the buffer in bytes if a * {@link BufferedInputStream} has to be created * @return {@code null} if the stream doesn't have more bytes, the provided * stream if the provided stream is markable and has more bytes, or * a {@link BufferedInputStream} if the provided stream is not * markable and has more bytes * * @throws IOException */ public static InputStream checkForBytes(InputStream stream, int bufferSize) throws IOException { if (stream == null) { return null; } InputStream checkStream = stream; if (!stream.markSupported()) { checkStream = new BufferedInputStream(stream, bufferSize); } if (checkForBytes(checkStream)) { return checkStream; } return null; }
stream = new BufferedInputStream(stream, 64 * 1024); try { hasResponseStream = IOUtils.checkForBytes(stream); } catch (IOException ioe) { throw new CmisConnectionException("IO exception!", ioe);
stream = new BufferedInputStream(stream, 64 * 1024); try { hasResponseStream = IOUtils.checkForBytes(stream); } catch (IOException ioe) { throw new CmisConnectionException("IO exception!", ioe);
@Override public FailedToDeleteData deleteTree(String repositoryId, String folderId, Boolean allVersions, UnfileObject unfileObjects, Boolean continueOnFailure, ExtensionsData extension) { // build URL UrlBuilder url = getObjectUrl(repositoryId, folderId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_DELETE_TREE); formData.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions); formData.addParameter(Constants.PARAM_UNFILE_OBJECTS, unfileObjects); formData.addParameter(Constants.PARAM_CONTINUE_ON_FAILURE, continueOnFailure); // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); if (resp.hasResponseStream()) { try { InputStream responseStream = IOUtils.checkForBytes(resp.getStream(), 8192); if (responseStream != null) { Map<String, Object> json = parseObject(responseStream, resp.getCharset()); return JSONConverter.convertFailedToDelete(json); } } catch (IOException e) { throw new CmisConnectionException("Cannot read response!", e); } } return new FailedToDeleteDataImpl(); }
@Override public FailedToDeleteData deleteTree(String repositoryId, String folderId, Boolean allVersions, UnfileObject unfileObjects, Boolean continueOnFailure, ExtensionsData extension) { // build URL UrlBuilder url = getObjectUrl(repositoryId, folderId); // prepare form data final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_DELETE_TREE); formData.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions); formData.addParameter(Constants.PARAM_UNFILE_OBJECTS, unfileObjects); formData.addParameter(Constants.PARAM_CONTINUE_ON_FAILURE, continueOnFailure); // send Response resp = post(url, formData.getContentType(), new Output() { @Override public void write(OutputStream out) throws IOException { formData.write(out); } }); if (resp.hasResponseStream()) { try { InputStream responseStream = IOUtils.checkForBytes(resp.getStream(), 8192); if (responseStream != null) { Map<String, Object> json = parseObject(responseStream, resp.getCharset()); return JSONConverter.convertFailedToDelete(json); } } catch (IOException e) { throw new CmisConnectionException("Cannot read response!", e); } } return new FailedToDeleteDataImpl(); }