Fix _design slash encoding bug:

Unit tests check push and pull works correctly
Merge pull request #23 from cloudant/29179-dont-encode-first-slash

Fix _design slash encoding bug:

Make a special case for _design/ in encodePathComponent()

Unit tests check push and pull works correctly
Replicate document attachments

This commit adds an implementation for sending and
retrieving attachments during both push and pull
replication.

For pulling attachments, the document is downloaded and
the attachment stubs in the JSON are used to download the
document's attachments before inserting the document into
the database.

Attachments are first downloaded into the blob store, then
a transaction is created in which we insert the document and
its attachments are added to the databases.

We also need to handle GZIPped attachments.

Finally we need to handle copying over stub attachments during
forceInsert of the new documents, as we avoid downloading the
blobs for attachments we already have by using atts_since.

For pushing attachments, attachments need to be sent along
with the document to avoid creating spurious document revisions.
We do this in two ways:

1. For documents with only small[1] attachments, the attachments
   are sent inline with the document's JSON during _bulk_docs
   posts.
2. For large attachments, documents are sent using a
   multipart/related call instead of via _bulk_docs. This PR
   includes a multipart/related encoder for this.

[1] Defined per replication with a 65k default
Only update registered indexes when calling updateAllIndexes

Previously, IndexManager would try to update all indexes that exist
in the index database. This would cause an exception for those which
hadn't been registered this session with ensureIndexed as the
indexing function for those indexes wasn't known.

This patch just excludes unregistered indexes from the update process
and adds a regression test.
Work-around for base64 issues:

Android uses an old version of commons-codec (1.2?) which doesn't have
Base64{Input,Output}Stream. Their version always takes priority so we can't use a newer version. So,
if running on android, use the android.util libraries for this purpose.

NB once the 31028-java-desktop-build branch is moved, the classes will need to be loaded by
class.forName() to de-couple them.
Merge pull request #26 from cloudant/commons-codec-base64-bug

Work-around for base64 issues:

Android uses an old version of commons-codec (1.2?) which doesn't have
Base64{Input,Output}Stream. Their version always takes priority so we can't use a newer version. So,
if running on android, use the android.util libraries for this purpose.

NB once the 31028-java-desktop-build branch is moved, the classes will need to be loaded by
class.forName() to de-couple them.
Fix bug stopping documents having the same attachment
Don't pull attachments we already have for a given revpos:

* Don't send atts_since when not pulling attachments inline (it doesn't make sense and will cause
  the attachments to be inlined anyway)

* Don't check "stub" value when not pulling attachments inline (they will always be stubbed, by
  definition)

* Use revpos of rev being added to determine whether we already have the attachments. Do this by
  looking back through the documentRevs object to see if we have the attachment for that generation
  in our bit of the tree.
Merge pull request #27 from cloudant/32319_duplicate_attachment

32319 duplicate attachment
Merge pull request #28 from cloudant/32354-dont-pull-attachments-revpos

Don't pull attachments we already have for a given revpos:

Don't send atts_since when not pulling attachments inline (it doesn't make sense and will cause
the attachments to be inlined anyway)

Don't check "stub" value when not pulling attachments inline (they will always be stubbed, by
definition)

Use revpos of rev being added to determine whether we already have the attachments. Do this by
looking back through the documentRevs object to see if we have the attachment for that generation
in our bit of the tree.
Send basic authenticate credentials preemptively

- Use AuthCache to send credentials preemptively
- Check if password and username are null or empty before attempting to send credentials
Merge pull request #29 from cloudant/32398_auth_initial_request

Enable preemptive authentication to reduce network requests
Some fixes on attachment writer:

* Flush and close base64 output stream
  This was previously causing a bug where the last byte wasn't always written

* More stringent check on TestUtils.streamsEqual()
  It wasn't failing when the second stream was longer

* Early exit on MultiPartAttachmentWriter.read()
  No point continuing when there are no more bytes left
Don't use InputStream.available() to determine how much to read.

I misunderstood the contract of this method, it will often return 0 on the Android implementation.
Return deleted revision from Datastore.deleteDocument
Multipart writer fixes:

* Simplify read() to be more efficient
* Rework read(byte[]) so it doesn't call available()
* Check result of AddImageAttachmentTest against known good output
  This uses % as a special metacharacter which stands for 'any character'
When inserting attachment into db, get the length from the temp file

This is the accurate length of the file since we have written all the bytes to disk.
Previously, this might have been inaccurate for attachments coming from streams etc.
Remove test changes_limitByOne_dbChangesMustReturnedAndLimitedByOne

This test is testing what the changes feed on Couch and Cloudant
returns rather than the library. Useful for understanding the
behaviour, but not required in the sync-android test suite.

FB 23931
Separate Java SE and Android build artifacts.

This allows developers to use our libraries on Java SE or Android platforms without bringing in
unnecessary extra dependencies.

There are now three sub-projects:

* sync-core
* sync-android
* sync-javase

This results in the following jars being published to the maven repo:

* cloudant-sync-datastore-core
* cloudant-sync-datastore-android
* cloudant-sync-datastore-javase
Merge pull request #25 from cloudant/31028-java-desktop-build

FB 31028: This PR splits the project into 3 jars, one core, one Android-specific, one Java SE specific