Return-Path: X-Original-To: apmail-chemistry-dev-archive@www.apache.org Delivered-To: apmail-chemistry-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D2C7BE60B for ; Thu, 28 Feb 2013 10:39:09 +0000 (UTC) Received: (qmail 8510 invoked by uid 500); 28 Feb 2013 10:39:09 -0000 Delivered-To: apmail-chemistry-dev-archive@chemistry.apache.org Received: (qmail 8316 invoked by uid 500); 28 Feb 2013 10:39:08 -0000 Mailing-List: contact dev-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list dev@chemistry.apache.org Received: (qmail 8277 invoked by uid 99); 28 Feb 2013 10:39:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Feb 2013 10:39:07 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of peter.schmidt@alfresco.com designates 207.126.144.115 as permitted sender) Received: from [207.126.144.115] (HELO eu1sys200aog103.obsmtp.com) (207.126.144.115) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 28 Feb 2013 10:39:01 +0000 Received: from mail-ee0-f70.google.com ([74.125.83.70]) (using TLSv1) by eu1sys200aob103.postini.com ([207.126.147.11]) with SMTP ID DSNKUS8zrnwAF9gAFZ3wtQy5xb4PFlsJv6Y5@postini.com; Thu, 28 Feb 2013 10:38:40 UTC Received: by mail-ee0-f70.google.com with SMTP id l10so2023232eei.5 for ; Thu, 28 Feb 2013 02:38:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=VqgaHtCCmUiSSDUiUBzS3AhWT8CjyZFHkigJtV8HOuw=; b=gMoNaJo4e/nXsYxjsbMFW6skwg/OrchGnnU4R94MBK52+U6RTZW2onQ+3B2imCC8AB KglkRUu3ybzoLJzFJkTvlh+EfCrwjx7yYvFQd9kUj+Tyobx0fiu+5LEgukExF9n+akHF CnbTalrUaNFsL+yfoZNnnM7VDj98KriXMukiZN+OcbldN6690TItHw71aXJV90sNQG5g DRGkHi+oEAfad5Xop4W+HPj8bpJYF5IJ7dvgx3avcDnZ4Wf05sJthWDxgNOVV2XBAbyK 504cTAFSk3e6gIVkh39VPXjZ2tXpEBtJ30ouQ/u0zzYuCZIooElFlpxJgTmh8ud+5TZu oW1w== X-Received: by 10.180.98.98 with SMTP id eh2mr10430151wib.7.1362047918583; Thu, 28 Feb 2013 02:38:38 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.180.98.98 with SMTP id eh2mr10430122wib.7.1362047918332; Thu, 28 Feb 2013 02:38:38 -0800 (PST) Received: by 10.194.179.230 with HTTP; Thu, 28 Feb 2013 02:38:38 -0800 (PST) In-Reply-To: References: Date: Thu, 28 Feb 2013 10:38:38 +0000 Message-ID: Subject: Re: Objective-CMIS: base64 input streaming From: Peter Schmidt To: dev@chemistry.apache.org Content-Type: multipart/alternative; boundary=bcaec555504056f6b804d6c67e98 X-Gm-Message-State: ALoCoQmBN6dhEHHf4V7a8N1tf/o35IiFObZImclxFXG4bAT3hxx2mD1ZpaYnHzK56VhvhwmoVPUf6yzeqPjnCCnjydizzeDmjLIJ1rVx1rFBupDqQPkv7NEwFQSC4FSHnbNaw9a6D8KWdtZY6GnaWCUKQwxw1cfKSqjSxUuK5P3oEmTIY5Ja6B0= X-Virus-Checked: Checked by ClamAV on apache.org --bcaec555504056f6b804d6c67e98 Content-Type: text/plain; charset=ISO-8859-1 Hi Joram actually the "byte jiggling" refers only to the fact that the "inner" read statement (i.e. from the original source) has to be a multiple of 3 until the stream end is reached. I.e. the buffer size for the "inner" read and the actual read are different. It then simply boils down to storing the remaining until the next read request from the HTTP connection. I tested it with different byte sizes, and in fact our unit tests in AlfrescoSDK as well as CMIS lib upload files of various sizes. Regards Peter On 28 February 2013 09:53, Joram Barrez wrote: > Yes, it does make sense. And I do agree that a stream implementation is > better than the tmp file approach. > > But te 'byte jiggling' makes me kinda nervous. There's plenty that can go > wrong once one decide to jiggle bytes ;-). So maybe add some more tests > with different types of files (very small, very large, etc...) to the test > suite so we have a bit more confidence in the implementation. > > > On Thu, Feb 28, 2013 at 10:35 AM, Peter Schmidt > wrote: > > > Hi Joram > > indeed it took a bit of byte jiggling. > > > > The trick is to read an integer multiple of 3 from the non-encoded source > > input stream. That way you guarantee that the base64 encoder won't pad > the > > encoded bytes with = at the end. > > The exception, of course, is when you reach the end of the source stream, > > where = padding is expected. > > > > The second trick is to write out as many bytes as are requested in the > > read:maxLength statement. This means, filling the buffer with XML and > > base64 encoded data - and storing the remainder in a tmp buffer until the > > next read. > > > > We also need to ensure that the base64 input stream returns "has bytes > > available" even if the source input stream is exhausted. > > > > I tested it in the XCode profiler, and the memory foot print seems to be > > comparable with what we had before. > > > > Hope that makes sense? > > > > Regards > > Peter > > > > > > > > On 28 February 2013 09:17, Joram Barrez wrote: > > > > > > when a read request is being sent to the new input stream class, the > > XML > > > > encapsulation and base64 encoding is done on the fly > > > > > > I remember I looked around for a streaming base64 implementation, but > > > couldn't find something ready to use in ios straight away. > > > > > > Are you using some library or are you keeping some characters in memory > > > until you have enough to do the encoding (like described eg in > > > > > > > > > http://stackoverflow.com/questions/7920780/is-it-possible-to-base64-encode-a-file-in-chunks > > > )? > > > > > > > > > > > > > > > On Thu, Feb 28, 2013 at 10:03 AM, Peter Schmidt > > > wrote: > > > > > > > Hi all > > > > just a brief heads-up: > > > > I am going to submit a change in the way content is being uploaded > from > > > the > > > > device to the server. > > > > How it works at present: > > > > * a temporary file is created containing the CMIS XML and base64 > > encoded > > > > data. > > > > * a NSInputStream pointing to the tmp file is created > > > > * the HTTP request BodyStream property is being set to this tmp input > > > > stream > > > > > > > > The new code will do the following: > > > > * a new class CMISBase64InputStream is being provided, which inherits > > > from > > > > NSInputStream. It is being initialised with the original source input > > > > stream (raw data). > > > > * the HTTP request BodyStream property is being set to the > > > > CMISBase64InputStream object. > > > > * when a read request is being sent to the new input stream class, > the > > > XML > > > > encapsulation and base64 encoding is done on the fly > > > > > > > > I tested it in both unit tests and a sample app, and it seems to > work. > > > > Unless there are objections, I will submit the new code by end of > play > > > > tomorrow, Fri 1 March > > > > > > > > -- > > > > Kind regards > > > > Peter > > > > > > > > ----------- > > > > *Peter Schmidt* > > > > *Alfresco Software Ltd.* > > > > *UK: 07748 185496* > > > > *Int.: 0044 7748 185496* > > > > *Skype: pweschmidt* > > > > > > > > > > > > > > > -- > > Kind regards > > Peter > > > > ----------- > > *Peter Schmidt* > > *Alfresco Software Ltd.* > > *UK: 07748 185496* > > *Int.: 0044 7748 185496* > > *Skype: pweschmidt* > > > -- Kind regards Peter ----------- *Peter Schmidt* *Alfresco Software Ltd.* *UK: 07748 185496* *Int.: 0044 7748 185496* *Skype: pweschmidt* --bcaec555504056f6b804d6c67e98--