diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 6cde2588..1f9aa651 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -7,9 +7,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/gradle@master + - name: Setup local.properties + run: | + cat << EOF >> local.properties + sdk.dir=$ANDROID_HOME + host="${{ secrets.HOST }}" + APIKey="${{ secrets.API_KEY }}" + deliveryToken="${{ secrets.DELIVERY_TOKEN }}" + environment="${{ secrets.ENVIRONMENT }}" + contentType="${{ secrets.CONTENT_TYPE }}" + assetUid="${{ secrets.ASSET_UID }}" + EOF + - uses: snyk/actions/setup@master + - run: snyk test --fail-on=all env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - with: - args: --fail-on=all --all-sub-projects \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 330d6032..bc2f6274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## Version 3.15.0 + +### Date: 20-May-2024 + +- Fixes and enhancements + +--- + ## Version 3.14.0 ### Date: 13-May-2024 diff --git a/contentstack/build.gradle b/contentstack/build.gradle index c7540b6e..035e17c7 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -10,7 +10,7 @@ android.buildFeatures.buildConfig true mavenPublishing { publishToMavenCentral(SonatypeHost.DEFAULT) signAllPublications() - coordinates("com.contentstack.sdk", "android", "3.14.0") + coordinates("com.contentstack.sdk", "android", "3.15.0") pom { name = "contentstack-android" @@ -146,6 +146,9 @@ dependencies { androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) + +// implementation 'com.squareup.okio:okio:3.9.0' + implementation 'com.github.rjeschke:txtmark:0.12' } tasks.register('clearJar', Delete) { delete 'build/libs/contentstack.jar' } tasks.register('unzip', Copy) { @@ -160,4 +163,4 @@ tasks.register('createJar', Jar) { include 'com/contentstack/' //include 'META-INF/' } -createJar.dependsOn(clearJar, unzip, build) +createJar.dependsOn(clearJar, unzip, build) \ No newline at end of file diff --git a/contentstack/src/main/java/com/contentstack/okio/AsyncTimeout.java b/contentstack/src/main/java/com/contentstack/okio/AsyncTimeout.java deleted file mode 100755 index d37f7e85..00000000 --- a/contentstack/src/main/java/com/contentstack/okio/AsyncTimeout.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.contentstack.okio; - -import java.io.IOException; -import java.io.InterruptedIOException; - -/** - * This timeout uses a background thread to take action exactly when the timeout - * occurs. Use this to implement timeouts where they aren't supported natively, - * such as to sockets that are blocked on writing. - * - *
Subclasses should override {@link #timedOut} to take action when a timeout - * occurs. This method will be invoked by the shared watchdog thread so it - * should not do any long-running operations. Otherwise we risk starving other - * timeouts from being triggered. - * - *
Use {@link #sink} and {@link #source} to apply this timeout to a stream. - * The returned value will apply the timeout to each operation on the wrapped - * stream. - * - *
Callers should call {@link #enter} before doing work that is subject to - * timeouts, and {@link #exit} afterwards. The return value of {@link #exit} - * indicates whether a timeout was triggered. Note that the call to {@link - * #timedOut} is asynchronous, and may be called after {@link #exit}. - */ -public class AsyncTimeout extends Timeout { - /** - * The watchdog thread processes a linked list of pending timeouts, sorted in - * the order to be triggered. This class synchronizes on AsyncTimeout.class. - * This lock guards the queue. - * - *
Head's 'next' points to the first element of the linked list. The first - * element is the next node to time out, or null if the queue is empty. The - * head is null until the watchdog thread is started. - */ - private static AsyncTimeout head; - - /** - * True if this node is currently in the queue. - */ - private boolean inQueue; - - /** - * The next node in the linked list. - */ - private AsyncTimeout next; - - /** - * If scheduled, this is the time that the watchdog should time this out. - */ - private long timeoutAt; - - public final void enter() { - if (inQueue) throw new IllegalStateException("Unbalanced enter/exit"); - long timeoutNanos = timeoutNanos(); - boolean hasDeadline = hasDeadline(); - if (timeoutNanos == 0 && !hasDeadline) { - return; // No timeout and no deadline? Don't bother with the queue. - } - inQueue = true; - scheduleTimeout(this, timeoutNanos, hasDeadline); - } - - private static synchronized void scheduleTimeout( - AsyncTimeout node, long timeoutNanos, boolean hasDeadline) { - // Start the watchdog thread and create the head node when the first timeout is scheduled. - if (head == null) { - head = new AsyncTimeout(); - new Watchdog().start(); - } - - long now = System.nanoTime(); - if (timeoutNanos != 0 && hasDeadline) { - // Compute the earliest event; either timeout or deadline. Because nanoTime can wrap around, - // Math.min() is undefined for absolute values, but meaningful for relative ones. - node.timeoutAt = now + Math.min(timeoutNanos, node.deadlineNanoTime() - now); - } else if (timeoutNanos != 0) { - node.timeoutAt = now + timeoutNanos; - } else if (hasDeadline) { - node.timeoutAt = node.deadlineNanoTime(); - } else { - throw new AssertionError(); - } - - // Insert the node in sorted order. - long remainingNanos = node.remainingNanos(now); - for (AsyncTimeout prev = head; true; prev = prev.next) { - if (prev.next == null || remainingNanos < prev.next.remainingNanos(now)) { - node.next = prev.next; - prev.next = node; - if (prev == head) { - AsyncTimeout.class.notify(); // Wake up the watchdog when inserting at the front. - } - break; - } - } - } - - /** - * Returns true if the timeout occurred. - */ - public final boolean exit() { - if (!inQueue) return false; - inQueue = false; - return cancelScheduledTimeout(this); - } - - /** - * Returns true if the timeout occurred. - */ - private static synchronized boolean cancelScheduledTimeout(AsyncTimeout node) { - // Remove the node from the linked list. - for (AsyncTimeout prev = head; prev != null; prev = prev.next) { - if (prev.next == node) { - prev.next = node.next; - node.next = null; - return false; - } - } - - // The node wasn't found in the linked list: it must have timed out! - return true; - } - - /** - * Returns the amount of time left until the time out. This will be negative - * if the timeout has elapsed and the timeout should occur immediately. - */ - private long remainingNanos(long now) { - return timeoutAt - now; - } - - /** - * Invoked by the watchdog thread when the time between calls to {@link - * #enter()} and {@link #exit()} has exceeded the timeout. - */ - protected void timedOut() { - } - - /** - * Returns a new sink that delegates to {@code sink}, using this to implement - * timeouts. This works best if {@link #timedOut} is overridden to interrupt - * {@code sink}'s current operation. - */ - public final Sink sink(final Sink sink) { - return new Sink() { - @Override - public void write(Buffer source, long byteCount) throws IOException { - boolean throwOnTimeout = false; - enter(); - try { - sink.write(source, byteCount); - throwOnTimeout = true; - } catch (IOException e) { - throw exit(e); - } finally { - exit(throwOnTimeout); - } - } - - @Override - public void flush() throws IOException { - boolean throwOnTimeout = false; - enter(); - try { - sink.flush(); - throwOnTimeout = true; - } catch (IOException e) { - throw exit(e); - } finally { - exit(throwOnTimeout); - } - } - - @Override - public void close() throws IOException { - boolean throwOnTimeout = false; - enter(); - try { - sink.close(); - throwOnTimeout = true; - } catch (IOException e) { - throw exit(e); - } finally { - exit(throwOnTimeout); - } - } - - @Override - public Timeout timeout() { - return AsyncTimeout.this; - } - - @Override - public String toString() { - return "AsyncTimeout.sink(" + sink + ")"; - } - }; - } - - /** - * Returns a new source that delegates to {@code source}, using this to - * implement timeouts. This works best if {@link #timedOut} is overridden to - * interrupt {@code sink}'s current operation. - */ - public final Source source(final Source source) { - return new Source() { - @Override - public long read(Buffer sink, long byteCount) throws IOException { - boolean throwOnTimeout = false; - enter(); - try { - long result = source.read(sink, byteCount); - throwOnTimeout = true; - return result; - } catch (IOException e) { - throw exit(e); - } finally { - exit(throwOnTimeout); - } - } - - @Override - public void close() throws IOException { - boolean throwOnTimeout = false; - try { - source.close(); - throwOnTimeout = true; - } catch (IOException e) { - throw exit(e); - } finally { - exit(throwOnTimeout); - } - } - - @Override - public Timeout timeout() { - return AsyncTimeout.this; - } - - @Override - public String toString() { - return "AsyncTimeout.source(" + source + ")"; - } - }; - } - - /** - * Throws an InterruptedIOException if {@code throwOnTimeout} is true and a - * timeout occurred. - */ - final void exit(boolean throwOnTimeout) throws IOException { - boolean timedOut = exit(); - if (timedOut && throwOnTimeout) throw new InterruptedIOException("timeout"); - } - - /** - * Returns either {@code cause} or an InterruptedIOException that's caused by - * {@code cause} if a timeout occurred. - */ - final IOException exit(IOException cause) throws IOException { - if (!exit()) return cause; - InterruptedIOException e = new InterruptedIOException("timeout"); - e.initCause(cause); - return e; - } - - private static final class Watchdog extends Thread { - public Watchdog() { - super("Okio Watchdog"); - setDaemon(true); - } - - public void run() { - while (true) { - try { - AsyncTimeout timedOut = awaitTimeout(); - - // Didn't find a node to interrupt. Try again. - if (timedOut == null) continue; - - // Close the timed out node. - timedOut.timedOut(); - } catch (InterruptedException ignored) { - } - } - } - } - - /** - * Removes and returns the node at the head of the list, waiting for it to - * time out if necessary. Returns null if the situation changes while waiting: - * either a newer node is inserted at the head, or the node being waited on - * has been removed. - */ - private static synchronized AsyncTimeout awaitTimeout() throws InterruptedException { - // Get the next eligible node. - AsyncTimeout node = head.next; - - // The queue is empty. Wait for something to be enqueued. - if (node == null) { - AsyncTimeout.class.wait(); - return null; - } - - long waitNanos = node.remainingNanos(System.nanoTime()); - - // The head of the queue hasn't timed out yet. Await that. - if (waitNanos > 0) { - // Waiting is made complicated by the fact that we work in nanoseconds, - // but the API wants (millis, nanos) in two arguments. - long waitMillis = waitNanos / 1000000L; - waitNanos -= (waitMillis * 1000000L); - AsyncTimeout.class.wait(waitMillis, (int) waitNanos); - return null; - } - - // The head of the queue has timed out. Remove it. - head.next = node.next; - node.next = null; - return node; - } -} diff --git a/contentstack/src/main/java/com/contentstack/okio/Base64.java b/contentstack/src/main/java/com/contentstack/okio/Base64.java deleted file mode 100755 index a93f9cf8..00000000 --- a/contentstack/src/main/java/com/contentstack/okio/Base64.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @author Alexander Y. Kleymenov - */ -package com.contentstack.okio; - -import java.io.UnsupportedEncodingException; - -final class Base64 { - private Base64() { - } - - public static byte[] decode(String in) { - // Ignore trailing '=' padding and whitespace from the input. - int limit = in.length(); - for (; limit > 0; limit--) { - char c = in.charAt(limit - 1); - if (c != '=' && c != '\n' && c != '\r' && c != ' ' && c != '\t') { - break; - } - } - - // If the input includes whitespace, this output array will be longer than necessary. - byte[] out = new byte[(int) (limit * 6L / 8L)]; - int outCount = 0; - int inCount = 0; - - int word = 0; - for (int pos = 0; pos < limit; pos++) { - char c = in.charAt(pos); - - int bits; - if (c >= 'A' && c <= 'Z') { - // char ASCII value - // A 65 0 - // Z 90 25 (ASCII - 65) - bits = c - 65; - } else if (c >= 'a' && c <= 'z') { - // char ASCII value - // a 97 26 - // z 122 51 (ASCII - 71) - bits = c - 71; - } else if (c >= '0' && c <= '9') { - // char ASCII value - // 0 48 52 - // 9 57 61 (ASCII + 4) - bits = c + 4; - } else if (c == '+') { - bits = 62; - } else if (c == '/') { - bits = 63; - } else if (c == '\n' || c == '\r' || c == ' ' || c == '\t') { - continue; - } else { - return null; - } - - // Append this char's 6 bits to the word. - word = (word << 6) | (byte) bits; - - // For every 4 chars of input, we accumulate 24 bits of output. Emit 3 bytes. - inCount++; - if (inCount % 4 == 0) { - out[outCount++] = (byte) (word >> 16); - out[outCount++] = (byte) (word >> 8); - out[outCount++] = (byte) word; - } - } - - int lastWordChars = inCount % 4; - if (lastWordChars == 1) { - // We read 1 char followed by "===". But 6 bits is a truncated byte! Fail. - return null; - } else if (lastWordChars == 2) { - // We read 2 chars followed by "==". Emit 1 byte with 8 of those 12 bits. - word = word << 12; - out[outCount++] = (byte) (word >> 16); - } else if (lastWordChars == 3) { - // We read 3 chars, followed by "=". Emit 2 bytes for 16 of those 18 bits. - word = word << 6; - out[outCount++] = (byte) (word >> 16); - out[outCount++] = (byte) (word >> 8); - } - - // If we sized our out array perfectly, we're done. - if (outCount == out.length) return out; - - // Copy the decoded bytes to a new, right-sized array. - byte[] prefix = new byte[outCount]; - System.arraycopy(out, 0, prefix, 0, outCount); - return prefix; - } - - private static final byte[] MAP = new byte[]{ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', - '5', '6', '7', '8', '9', '+', '/' - }; - - public static String encode(byte[] in) { - int length = (in.length + 2) * 4 / 3; - byte[] out = new byte[length]; - int index = 0, end = in.length - in.length % 3; - for (int i = 0; i < end; i += 3) { - out[index++] = MAP[(in[i] & 0xff) >> 2]; - out[index++] = MAP[((in[i] & 0x03) << 4) | ((in[i + 1] & 0xff) >> 4)]; - out[index++] = MAP[((in[i + 1] & 0x0f) << 2) | ((in[i + 2] & 0xff) >> 6)]; - out[index++] = MAP[(in[i + 2] & 0x3f)]; - } - switch (in.length % 3) { - case 1: - out[index++] = MAP[(in[end] & 0xff) >> 2]; - out[index++] = MAP[(in[end] & 0x03) << 4]; - out[index++] = '='; - out[index++] = '='; - break; - case 2: - out[index++] = MAP[(in[end] & 0xff) >> 2]; - out[index++] = MAP[((in[end] & 0x03) << 4) | ((in[end + 1] & 0xff) >> 4)]; - out[index++] = MAP[((in[end + 1] & 0x0f) << 2)]; - out[index++] = '='; - break; - } - try { - return new String(out, 0, index, "US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } - } -} diff --git a/contentstack/src/main/java/com/contentstack/okio/Buffer.java b/contentstack/src/main/java/com/contentstack/okio/Buffer.java deleted file mode 100755 index dbb7c125..00000000 --- a/contentstack/src/main/java/com/contentstack/okio/Buffer.java +++ /dev/null @@ -1,1032 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.contentstack.okio; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.contentstack.okio.Util.checkOffsetAndCount; -import static com.contentstack.okio.Util.reverseBytesLong; - -/** - * A collection of bytes in memory. - * - *
Moving data from one buffer to another is fast. Instead - * of copying bytes from one place in memory to another, this class just changes - * ownership of the underlying byte arrays. - * - *
This buffer grows with your data. Just like ArrayList, - * each buffer starts small. It consumes only the memory it needs to. - * - *
This buffer pools its byte arrays. When you allocate a
- * byte array in Java, the runtime must zero-fill the requested array before
- * returning it to you. Even if you're going to write over that space anyway.
- * This class avoids zero-fill and GC churn by pooling byte arrays.
- */
-public final class Buffer implements BufferedSource, BufferedSink, Cloneable {
- Segment head;
- long size;
-
- public Buffer() {
- }
-
- /**
- * Returns the number of bytes currently in this buffer.
- */
- public long size() {
- return size;
- }
-
- @Override
- public Buffer buffer() {
- return this;
- }
-
- @Override
- public OutputStream outputStream() {
- return new OutputStream() {
- @Override
- public void write(int b) {
- writeByte((byte) b);
- }
-
- @Override
- public void write(byte[] data, int offset, int byteCount) {
- Buffer.this.write(data, offset, byteCount);
- }
-
- @Override
- public void flush() {
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public String toString() {
- return this + ".outputStream()";
- }
- };
- }
-
- @Override
- public Buffer emitCompleteSegments() {
- return this; // Nowhere to emit to!
- }
-
- @Override
- public boolean exhausted() {
- return size == 0;
- }
-
- @Override
- public void require(long byteCount) throws EOFException {
- if (this.size < byteCount) throw new EOFException();
- }
-
- @Override
- public boolean request(long byteCount) throws IOException {
- return size >= byteCount;
- }
-
- @Override
- public InputStream inputStream() {
- return new InputStream() {
- @Override
- public int read() {
- if (size > 0) return readByte() & 0xff;
- return -1;
- }
-
- @Override
- public int read(byte[] sink, int offset, int byteCount) {
- return Buffer.this.read(sink, offset, byteCount);
- }
-
- @Override
- public int available() {
- return (int) Math.min(size, Integer.MAX_VALUE);
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public String toString() {
- return Buffer.this + ".inputStream()";
- }
- };
- }
-
- /**
- * Copy the contents of this to {@code out}.
- */
- public Buffer copyTo(OutputStream out) throws IOException {
- return copyTo(out, 0, size);
- }
-
- /**
- * Copy {@code byteCount} bytes from this, starting at {@code offset}, to
- * {@code out}.
- */
- public Buffer copyTo(OutputStream out, long offset, long byteCount) throws IOException {
- if (out == null) throw new IllegalArgumentException("out == null");
- checkOffsetAndCount(size, offset, byteCount);
- if (byteCount == 0) return this;
-
- // Skip segments that we aren't copying from.
- Segment s = head;
- for (; offset >= (s.limit - s.pos); s = s.next) {
- offset -= (s.limit - s.pos);
- }
-
- // Copy from one segment at a time.
- for (; byteCount > 0; s = s.next) {
- int pos = (int) (s.pos + offset);
- int toWrite = (int) Math.min(s.limit - pos, byteCount);
- out.write(s.data, pos, toWrite);
- byteCount -= toWrite;
- offset = 0;
- }
-
- return this;
- }
-
- /**
- * Write the contents of this to {@code out}.
- */
- public Buffer writeTo(OutputStream out) throws IOException {
- return writeTo(out, size);
- }
-
- /**
- * Write {@code byteCount} bytes from this to {@code out}.
- */
- public Buffer writeTo(OutputStream out, long byteCount) throws IOException {
- if (out == null) throw new IllegalArgumentException("out == null");
- checkOffsetAndCount(size, 0, byteCount);
-
- Segment s = head;
- while (byteCount > 0) {
- int toCopy = (int) Math.min(byteCount, s.limit - s.pos);
- out.write(s.data, s.pos, toCopy);
-
- s.pos += toCopy;
- size -= toCopy;
- byteCount -= toCopy;
-
- if (s.pos == s.limit) {
- Segment toRecycle = s;
- head = s = toRecycle.pop();
- SegmentPool.INSTANCE.recycle(toRecycle);
- }
- }
-
- return this;
- }
-
- /**
- * Read and exhaust bytes from {@code in} to this.
- */
- public Buffer readFrom(InputStream in) throws IOException {
- readFrom(in, Long.MAX_VALUE, true);
- return this;
- }
-
- /**
- * Read {@code byteCount} bytes from {@code in} to this.
- */
- public Buffer readFrom(InputStream in, long byteCount) throws IOException {
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- readFrom(in, byteCount, false);
- return this;
- }
-
- private void readFrom(InputStream in, long byteCount, boolean forever) throws IOException {
- if (in == null) throw new IllegalArgumentException("in == null");
- while (byteCount > 0 || forever) {
- Segment tail = writableSegment(1);
- int maxToCopy = (int) Math.min(byteCount, Segment.SIZE - tail.limit);
- int bytesRead = in.read(tail.data, tail.limit, maxToCopy);
- if (bytesRead == -1) {
- if (forever) return;
- throw new EOFException();
- }
- tail.limit += bytesRead;
- size += bytesRead;
- byteCount -= bytesRead;
- }
- }
-
- /**
- * Returns the number of bytes in segments that are not writable. This is the
- * number of bytes that can be flushed immediately to an underlying sink
- * without harming throughput.
- */
- public long completeSegmentByteCount() {
- long result = size;
- if (result == 0) return 0;
-
- // Omit the tail if it's still writable.
- Segment tail = head.prev;
- if (tail.limit < Segment.SIZE) {
- result -= tail.limit - tail.pos;
- }
-
- return result;
- }
-
- @Override
- public byte readByte() {
- if (size == 0) throw new IllegalStateException("size == 0");
-
- Segment segment = head;
- int pos = segment.pos;
- int limit = segment.limit;
-
- byte[] data = segment.data;
- byte b = data[pos++];
- size -= 1;
-
- if (pos == limit) {
- head = segment.pop();
- SegmentPool.INSTANCE.recycle(segment);
- } else {
- segment.pos = pos;
- }
-
- return b;
- }
-
- /**
- * Returns the byte at {@code pos}.
- */
- public byte getByte(long pos) {
- checkOffsetAndCount(size, pos, 1);
- for (Segment s = head; true; s = s.next) {
- int segmentByteCount = s.limit - s.pos;
- if (pos < segmentByteCount) return s.data[s.pos + (int) pos];
- pos -= segmentByteCount;
- }
- }
-
- @Override
- public short readShort() {
- if (size < 2) throw new IllegalStateException("size < 2: " + size);
-
- Segment segment = head;
- int pos = segment.pos;
- int limit = segment.limit;
-
- // If the short is split across multiple segments, delegate to readByte().
- if (limit - pos < 2) {
- int s = (readByte() & 0xff) << 8
- | (readByte() & 0xff);
- return (short) s;
- }
-
- byte[] data = segment.data;
- int s = (data[pos++] & 0xff) << 8
- | (data[pos++] & 0xff);
- size -= 2;
-
- if (pos == limit) {
- head = segment.pop();
- SegmentPool.INSTANCE.recycle(segment);
- } else {
- segment.pos = pos;
- }
-
- return (short) s;
- }
-
- @Override
- public int readInt() {
- if (size < 4) throw new IllegalStateException("size < 4: " + size);
-
- Segment segment = head;
- int pos = segment.pos;
- int limit = segment.limit;
-
- // If the int is split across multiple segments, delegate to readByte().
- if (limit - pos < 4) {
- return (readByte() & 0xff) << 24
- | (readByte() & 0xff) << 16
- | (readByte() & 0xff) << 8
- | (readByte() & 0xff);
- }
-
- byte[] data = segment.data;
- int i = (data[pos++] & 0xff) << 24
- | (data[pos++] & 0xff) << 16
- | (data[pos++] & 0xff) << 8
- | (data[pos++] & 0xff);
- size -= 4;
-
- if (pos == limit) {
- head = segment.pop();
- SegmentPool.INSTANCE.recycle(segment);
- } else {
- segment.pos = pos;
- }
-
- return i;
- }
-
- @Override
- public long readLong() {
- if (size < 8) throw new IllegalStateException("size < 8: " + size);
-
- Segment segment = head;
- int pos = segment.pos;
- int limit = segment.limit;
-
- // If the long is split across multiple segments, delegate to readInt().
- if (limit - pos < 8) {
- return (readInt() & 0xffffffffL) << 32
- | (readInt() & 0xffffffffL);
- }
-
- byte[] data = segment.data;
- long v = (data[pos++] & 0xffL) << 56
- | (data[pos++] & 0xffL) << 48
- | (data[pos++] & 0xffL) << 40
- | (data[pos++] & 0xffL) << 32
- | (data[pos++] & 0xffL) << 24
- | (data[pos++] & 0xffL) << 16
- | (data[pos++] & 0xffL) << 8
- | (data[pos++] & 0xffL);
- size -= 8;
-
- if (pos == limit) {
- head = segment.pop();
- SegmentPool.INSTANCE.recycle(segment);
- } else {
- segment.pos = pos;
- }
-
- return v;
- }
-
- @Override
- public short readShortLe() {
- return Util.reverseBytesShort(readShort());
- }
-
- @Override
- public int readIntLe() {
- return Util.reverseBytesInt(readInt());
- }
-
- @Override
- public long readLongLe() {
- return Util.reverseBytesLong(readLong());
- }
-
- @Override
- public ByteString readByteString() {
- return new ByteString(readByteArray());
- }
-
- @Override
- public ByteString readByteString(long byteCount) throws EOFException {
- return new ByteString(readByteArray(byteCount));
- }
-
- @Override
- public void readFully(Buffer sink, long byteCount) throws EOFException {
- if (size < byteCount) {
- sink.write(this, size); // Exhaust ourselves.
- throw new EOFException();
- }
- sink.write(this, byteCount);
- }
-
- @Override
- public long readAll(Sink sink) throws IOException {
- long byteCount = size;
- if (byteCount > 0) {
- sink.write(this, byteCount);
- }
- return byteCount;
- }
-
- @Override
- public String readUtf8() {
- try {
- return readString(size, Util.UTF_8);
- } catch (EOFException e) {
- throw new AssertionError(e);
- }
- }
-
- @Override
- public String readUtf8(long byteCount) throws EOFException {
- return readString(byteCount, Util.UTF_8);
- }
-
- @Override
- public String readString(Charset charset) {
- try {
- return readString(size, charset);
- } catch (EOFException e) {
- throw new AssertionError(e);
- }
- }
-
- @Override
- public String readString(long byteCount, Charset charset) throws EOFException {
- checkOffsetAndCount(size, 0, byteCount);
- if (charset == null) throw new IllegalArgumentException("charset == null");
- if (byteCount > Integer.MAX_VALUE) {
- throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + byteCount);
- }
- if (byteCount == 0) return "";
-
- Segment head = this.head;
- if (head.pos + byteCount > head.limit) {
- // If the string spans multiple segments, delegate to readBytes().
- return new String(readByteArray(byteCount), charset);
- }
-
- String result = new String(head.data, head.pos, (int) byteCount, charset);
- head.pos += byteCount;
- size -= byteCount;
-
- if (head.pos == head.limit) {
- this.head = head.pop();
- SegmentPool.INSTANCE.recycle(head);
- }
-
- return result;
- }
-
- @Override
- public String readUtf8Line() throws EOFException {
- long newline = indexOf((byte) '\n');
-
- if (newline == -1) {
- return size != 0 ? readUtf8(size) : null;
- }
-
- return readUtf8Line(newline);
- }
-
- @Override
- public String readUtf8LineStrict() throws EOFException {
- long newline = indexOf((byte) '\n');
- if (newline == -1) throw new EOFException();
- return readUtf8Line(newline);
- }
-
- String readUtf8Line(long newline) throws EOFException {
- if (newline > 0 && getByte(newline - 1) == '\r') {
- // Read everything until '\r\n', then skip the '\r\n'.
- String result = readUtf8((newline - 1));
- skip(2);
- return result;
-
- } else {
- // Read everything until '\n', then skip the '\n'.
- String result = readUtf8(newline);
- skip(1);
- return result;
- }
- }
-
- @Override
- public byte[] readByteArray() {
- try {
- return readByteArray(size);
- } catch (EOFException e) {
- throw new AssertionError(e);
- }
- }
-
- @Override
- public byte[] readByteArray(long byteCount) throws EOFException {
- checkOffsetAndCount(this.size, 0, byteCount);
- if (byteCount > Integer.MAX_VALUE) {
- throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + byteCount);
- }
-
- byte[] result = new byte[(int) byteCount];
- readFully(result);
- return result;
- }
-
- @Override
- public int read(byte[] sink) {
- return read(sink, 0, sink.length);
- }
-
- @Override
- public void readFully(byte[] sink) throws EOFException {
- int offset = 0;
- while (offset < sink.length) {
- int read = read(sink, offset, sink.length - offset);
- if (read == -1) throw new EOFException();
- offset += read;
- }
- }
-
- @Override
- public int read(byte[] sink, int offset, int byteCount) {
- checkOffsetAndCount(sink.length, offset, byteCount);
-
- Segment s = this.head;
- if (s == null) return -1;
- int toCopy = Math.min(byteCount, s.limit - s.pos);
- System.arraycopy(s.data, s.pos, sink, offset, toCopy);
-
- s.pos += toCopy;
- this.size -= toCopy;
-
- if (s.pos == s.limit) {
- this.head = s.pop();
- SegmentPool.INSTANCE.recycle(s);
- }
-
- return toCopy;
- }
-
- /**
- * Discards all bytes in this buffer. Calling this method when you're done
- * with a buffer will return its segments to the pool.
- */
- public void clear() {
- try {
- skip(size);
- } catch (EOFException e) {
- throw new AssertionError(e);
- }
- }
-
- /**
- * Discards {@code byteCount} bytes from the head of this buffer.
- */
- @Override
- public void skip(long byteCount) throws EOFException {
- while (byteCount > 0) {
- if (head == null) throw new EOFException();
-
- int toSkip = (int) Math.min(byteCount, head.limit - head.pos);
- size -= toSkip;
- byteCount -= toSkip;
- head.pos += toSkip;
-
- if (head.pos == head.limit) {
- Segment toRecycle = head;
- head = toRecycle.pop();
- SegmentPool.INSTANCE.recycle(toRecycle);
- }
- }
- }
-
- @Override
- public Buffer write(ByteString byteString) {
- if (byteString == null) throw new IllegalArgumentException("byteString == null");
- return write(byteString.data, 0, byteString.data.length);
- }
-
- @Override
- public Buffer writeUtf8(String string) {
- if (string == null) throw new IllegalArgumentException("string == null");
- return writeString(string, Util.UTF_8);
- }
-
- @Override
- public Buffer writeString(String string, Charset charset) {
- if (string == null) throw new IllegalArgumentException("string == null");
- if (charset == null) throw new IllegalArgumentException("charset == null");
- byte[] data = string.getBytes(charset);
- return write(data, 0, data.length);
- }
-
- @Override
- public Buffer write(byte[] source) {
- if (source == null) throw new IllegalArgumentException("source == null");
- return write(source, 0, source.length);
- }
-
- @Override
- public Buffer write(byte[] source, int offset, int byteCount) {
- if (source == null) throw new IllegalArgumentException("source == null");
- checkOffsetAndCount(source.length, offset, byteCount);
-
- int limit = offset + byteCount;
- while (offset < limit) {
- Segment tail = writableSegment(1);
-
- int toCopy = Math.min(limit - offset, Segment.SIZE - tail.limit);
- System.arraycopy(source, offset, tail.data, tail.limit, toCopy);
-
- offset += toCopy;
- tail.limit += toCopy;
- }
-
- this.size += byteCount;
- return this;
- }
-
- @Override
- public long writeAll(Source source) throws IOException {
- if (source == null) throw new IllegalArgumentException("source == null");
- long totalBytesRead = 0;
- for (long readCount; (readCount = source.read(this, Segment.SIZE)) != -1; ) {
- totalBytesRead += readCount;
- }
- return totalBytesRead;
- }
-
- @Override
- public Buffer writeByte(int b) {
- Segment tail = writableSegment(1);
- tail.data[tail.limit++] = (byte) b;
- size += 1;
- return this;
- }
-
- @Override
- public Buffer writeShort(int s) {
- Segment tail = writableSegment(2);
- byte[] data = tail.data;
- int limit = tail.limit;
- data[limit++] = (byte) ((s >>> 8) & 0xff);
- data[limit++] = (byte) (s & 0xff);
- tail.limit = limit;
- size += 2;
- return this;
- }
-
- @Override
- public Buffer writeShortLe(int s) {
- return writeShort(Util.reverseBytesShort((short) s));
- }
-
- @Override
- public Buffer writeInt(int i) {
- Segment tail = writableSegment(4);
- byte[] data = tail.data;
- int limit = tail.limit;
- data[limit++] = (byte) ((i >>> 24) & 0xff);
- data[limit++] = (byte) ((i >>> 16) & 0xff);
- data[limit++] = (byte) ((i >>> 8) & 0xff);
- data[limit++] = (byte) (i & 0xff);
- tail.limit = limit;
- size += 4;
- return this;
- }
-
- @Override
- public Buffer writeIntLe(int i) {
- return writeInt(Util.reverseBytesInt(i));
- }
-
- @Override
- public Buffer writeLong(long v) {
- Segment tail = writableSegment(8);
- byte[] data = tail.data;
- int limit = tail.limit;
- data[limit++] = (byte) ((v >>> 56L) & 0xff);
- data[limit++] = (byte) ((v >>> 48L) & 0xff);
- data[limit++] = (byte) ((v >>> 40L) & 0xff);
- data[limit++] = (byte) ((v >>> 32L) & 0xff);
- data[limit++] = (byte) ((v >>> 24L) & 0xff);
- data[limit++] = (byte) ((v >>> 16L) & 0xff);
- data[limit++] = (byte) ((v >>> 8L) & 0xff);
- data[limit++] = (byte) (v & 0xff);
- tail.limit = limit;
- size += 8;
- return this;
- }
-
- @Override
- public Buffer writeLongLe(long v) {
- return writeLong(reverseBytesLong(v));
- }
-
- /**
- * Returns a tail segment that we can write at least {@code minimumCapacity}
- * bytes to, creating it if necessary.
- */
- Segment writableSegment(int minimumCapacity) {
- if (minimumCapacity < 1 || minimumCapacity > Segment.SIZE)
- throw new IllegalArgumentException();
-
- if (head == null) {
- head = SegmentPool.INSTANCE.take(); // Acquire a first segment.
- return head.next = head.prev = head;
- }
-
- Segment tail = head.prev;
- if (tail.limit + minimumCapacity > Segment.SIZE) {
- tail = tail.push(SegmentPool.INSTANCE.take()); // Append a new empty segment to fill up.
- }
- return tail;
- }
-
- @Override
- public void write(Buffer source, long byteCount) {
- // Move bytes from the head of the source buffer to the tail of this buffer
- // while balancing two conflicting goals: don't waste CPU and don't waste
- // memory.
- //
- //
- // Don't waste CPU (ie. don't copy data around).
- //
- // Copying large amounts of data is expensive. Instead, we prefer to
- // reassign entire segments from one buffer to the other.
- //
- //
- // Don't waste memory.
- //
- // As an invariant, adjacent pairs of segments in a buffer should be at
- // least 50% full, except for the head segment and the tail segment.
- //
- // The head segment cannot maintain the invariant because the application is
- // consuming bytes from this segment, decreasing its level.
- //
- // The tail segment cannot maintain the invariant because the application is
- // producing bytes, which may require new nearly-empty tail segments to be
- // appended.
- //
- //
- // Moving segments between buffers
- //
- // When writing one buffer to another, we prefer to reassign entire segments
- // over copying bytes into their most compact form. Suppose we have a buffer
- // with these segment levels [91%, 61%]. If we append a buffer with a
- // single [72%] segment, that yields [91%, 61%, 72%]. No bytes are copied.
- //
- // Or suppose we have a buffer with these segment levels: [100%, 2%], and we
- // want to append it to a buffer with these segment levels [99%, 3%]. This
- // operation will yield the following segments: [100%, 2%, 99%, 3%]. That
- // is, we do not spend time copying bytes around to achieve more efficient
- // memory use like [100%, 100%, 4%].
- //
- // When combining buffers, we will compact adjacent buffers when their
- // combined level doesn't exceed 100%. For example, when we start with
- // [100%, 40%] and append [30%, 80%], the result is [100%, 70%, 80%].
- //
- //
- // Splitting segments
- //
- // Occasionally we write only part of a source buffer to a sink buffer. For
- // example, given a sink [51%, 91%], we may want to write the first 30% of
- // a source [92%, 82%] to it. To simplify, we first transform the source to
- // an equivalent buffer [30%, 62%, 82%] and then move the head segment,
- // yielding sink [51%, 91%, 30%] and source [62%, 82%].
-
- if (source == null) throw new IllegalArgumentException("source == null");
- if (source == this) throw new IllegalArgumentException("source == this");
- checkOffsetAndCount(source.size, 0, byteCount);
-
- while (byteCount > 0) {
- // Is a prefix of the source's head segment all that we need to move?
- if (byteCount < (source.head.limit - source.head.pos)) {
- Segment tail = head != null ? head.prev : null;
- if (tail == null || byteCount + (tail.limit - tail.pos) > Segment.SIZE) {
- // We're going to need another segment. Split the source's head
- // segment in two, then move the first of those two to this buffer.
- source.head = source.head.split((int) byteCount);
- } else {
- // Our existing segments are sufficient. Move bytes from source's head to our tail.
- source.head.writeTo(tail, (int) byteCount);
- source.size -= byteCount;
- this.size += byteCount;
- return;
- }
- }
-
- // Remove the source's head segment and append it to our tail.
- Segment segmentToMove = source.head;
- long movedByteCount = segmentToMove.limit - segmentToMove.pos;
- source.head = segmentToMove.pop();
- if (head == null) {
- head = segmentToMove;
- head.next = head.prev = head;
- } else {
- Segment tail = head.prev;
- tail = tail.push(segmentToMove);
- tail.compact();
- }
- source.size -= movedByteCount;
- this.size += movedByteCount;
- byteCount -= movedByteCount;
- }
- }
-
- @Override
- public long read(Buffer sink, long byteCount) {
- if (sink == null) throw new IllegalArgumentException("sink == null");
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (this.size == 0) return -1L;
- if (byteCount > this.size) byteCount = this.size;
- sink.write(this, byteCount);
- return byteCount;
- }
-
- @Override
- public long indexOf(byte b) {
- return indexOf(b, 0);
- }
-
- /**
- * Returns the index of {@code b} in this at or beyond {@code fromIndex}, or
- * -1 if this buffer does not contain {@code b} in that range.
- */
- @Override
- public long indexOf(byte b, long fromIndex) {
- if (fromIndex < 0) throw new IllegalArgumentException("fromIndex < 0");
-
- Segment s = head;
- if (s == null) return -1L;
- long offset = 0L;
- do {
- int segmentByteCount = s.limit - s.pos;
- if (fromIndex >= segmentByteCount) {
- fromIndex -= segmentByteCount;
- } else {
- byte[] data = s.data;
- for (long pos = s.pos + fromIndex, limit = s.limit; pos < limit; pos++) {
- if (data[(int) pos] == b) return offset + pos - s.pos;
- }
- fromIndex = 0;
- }
- offset += segmentByteCount;
- s = s.next;
- } while (s != head);
- return -1L;
- }
-
- @Override
- public long indexOfElement(ByteString targetBytes) {
- return indexOfElement(targetBytes, 0);
- }
-
- @Override
- public long indexOfElement(ByteString targetBytes, long fromIndex) {
- if (fromIndex < 0) throw new IllegalArgumentException("fromIndex < 0");
-
- Segment s = head;
- if (s == null) return -1L;
- long offset = 0L;
- byte[] toFind = targetBytes.data;
- do {
- int segmentByteCount = s.limit - s.pos;
- if (fromIndex >= segmentByteCount) {
- fromIndex -= segmentByteCount;
- } else {
- byte[] data = s.data;
- for (long pos = s.pos + fromIndex, limit = s.limit; pos < limit; pos++) {
- byte b = data[(int) pos];
- for (byte targetByte : toFind) {
- if (b == targetByte) return offset + pos - s.pos;
- }
- }
- fromIndex = 0;
- }
- offset += segmentByteCount;
- s = s.next;
- } while (s != head);
- return -1L;
- }
-
- @Override
- public void flush() {
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public Timeout timeout() {
- return Timeout.NONE;
- }
-
- /**
- * For testing. This returns the sizes of the segments in this buffer.
- */
- List On the end of the stream this method returns null, just
- * like {@link java.io.BufferedReader}. If the source doesn't end with a line
- * break then an implicit line break is assumed. Null is returned once the
- * source is exhausted. Use this for human-generated data, where a trailing
- * line break is optional.
- */
- String readUtf8Line() throws IOException;
-
- /**
- * Removes and returns characters up to but not including the next line break.
- * A line break is either {@code "\n"} or {@code "\r\n"}; these characters are
- * not included in the result.
- *
- * On the end of the stream this method throws. Every call
- * must consume either '\r\n' or '\n'. If these characters are absent in the
- * stream, an {@link java.io.EOFException} is thrown. Use this for
- * machine-generated data where a missing line break implies truncated input.
- */
- String readUtf8LineStrict() throws IOException;
-
- /**
- * Removes all bytes from this, decodes them as {@code charset}, and returns
- * the string.
- */
- String readString(Charset charset) throws IOException;
-
- /**
- * Removes {@code byteCount} bytes from this, decodes them as {@code charset},
- * and returns the string.
- */
- String readString(long byteCount, Charset charset) throws IOException;
-
- /**
- * Returns the index of the first {@code b} in the buffer. This expands the
- * buffer as necessary until {@code b} is found. This reads an unbounded
- * number of bytes into the buffer. Returns -1 if the stream is exhausted
- * before the requested byte is found.
- */
- long indexOf(byte b) throws IOException;
-
- /**
- * Returns the index of the first {@code b} in the buffer at or after {@code
- * fromIndex}. This expands the buffer as necessary until {@code b} is found.
- * This reads an unbounded number of bytes into the buffer. Returns -1 if the
- * stream is exhausted before the requested byte is found.
- */
- long indexOf(byte b, long fromIndex) throws IOException;
-
- /**
- * Returns the index of the first byte in {@code targetBytes} in the buffer.
- * This expands the buffer as necessary until a target byte is found. This
- * reads an unbounded number of bytes into the buffer. Returns -1 if the
- * stream is exhausted before the requested byte is found.
- */
- long indexOfElement(ByteString targetBytes) throws IOException;
-
- /**
- * Returns the index of the first byte in {@code targetBytes} in the buffer
- * at or after {@code fromIndex}. This expands the buffer as necessary until
- * a target byte is found. This reads an unbounded number of bytes into the
- * buffer. Returns -1 if the stream is exhausted before the requested byte is
- * found.
- */
- long indexOfElement(ByteString targetBytes, long fromIndex) throws IOException;
-
- /**
- * Returns an input stream that reads from this source.
- */
- InputStream inputStream();
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/ByteString.java b/contentstack/src/main/java/com/contentstack/okio/ByteString.java
deleted file mode 100755
index 3bab9ef8..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/ByteString.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright 2014 Square Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-/**
- * An immutable sequence of bytes.
- *
- * Full disclosure: this class provides untrusted input and
- * output streams with raw access to the underlying byte array. A hostile
- * stream implementation could keep a reference to the mutable byte string,
- * violating the immutable guarantee of this class. For this reason a byte
- * string's immutability guarantee cannot be relied upon for security in applets
- * and other environments that run both trusted and untrusted code in the same
- * process.
- */
-public final class ByteString implements Serializable {
- private static final char[] HEX_DIGITS =
- {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
- private static final long serialVersionUID = 1L;
-
- /**
- * A singleton empty {@code ByteString}.
- */
- public static final ByteString EMPTY = ByteString.of();
-
- final byte[] data;
- private transient int hashCode; // Lazily computed; 0 if unknown.
- private transient String utf8; // Lazily computed.
-
- ByteString(byte[] data) {
- this.data = data; // Trusted internal constructor doesn't clone data.
- }
-
- /**
- * Returns a new byte string containing a clone of the bytes of {@code data}.
- */
- public static ByteString of(byte... data) {
- if (data == null) throw new IllegalArgumentException("data == null");
- return new ByteString(data.clone());
- }
-
- /**
- * Returns a new byte string containing a copy of {@code byteCount} bytes of {@code data} starting
- * at {@code offset}.
- */
- public static ByteString of(byte[] data, int offset, int byteCount) {
- if (data == null) throw new IllegalArgumentException("data == null");
- Util.checkOffsetAndCount(data.length, offset, byteCount);
-
- byte[] copy = new byte[byteCount];
- System.arraycopy(data, offset, copy, 0, byteCount);
- return new ByteString(copy);
- }
-
- /**
- * Returns a new byte string containing the {@code UTF-8} bytes of {@code s}.
- */
- public static ByteString encodeUtf8(String s) {
- if (s == null) throw new IllegalArgumentException("s == null");
- ByteString byteString = new ByteString(s.getBytes(Util.UTF_8));
- byteString.utf8 = s;
- return byteString;
- }
-
- /**
- * Constructs a new {@code String} by decoding the bytes as {@code UTF-8}.
- */
- public String utf8() {
- String result = utf8;
- // We don't care if we double-allocate in racy code.
- return result != null ? result : (utf8 = new String(data, Util.UTF_8));
- }
-
- /**
- * Returns this byte string encoded as Base64. In violation of the
- * RFC, the returned string does not wrap lines at 76 columns.
- */
- public String base64() {
- return Base64.encode(data);
- }
-
- /**
- * Decodes the Base64-encoded bytes and returns their value as a byte string.
- * Returns null if {@code base64} is not a Base64-encoded sequence of bytes.
- */
- public static ByteString decodeBase64(String base64) {
- if (base64 == null) throw new IllegalArgumentException("base64 == null");
- byte[] decoded = Base64.decode(base64);
- return decoded != null ? new ByteString(decoded) : null;
- }
-
- /**
- * Returns this byte string encoded in hexadecimal.
- */
- public String hex() {
- char[] result = new char[data.length * 2];
- int c = 0;
- for (byte b : data) {
- result[c++] = HEX_DIGITS[(b >> 4) & 0xf];
- result[c++] = HEX_DIGITS[b & 0xf];
- }
- return new String(result);
- }
-
- /**
- * Decodes the hex-encoded bytes and returns their value a byte string.
- */
- public static ByteString decodeHex(String hex) {
- if (hex == null) throw new IllegalArgumentException("hex == null");
- if (hex.length() % 2 != 0)
- throw new IllegalArgumentException("Unexpected hex string: " + hex);
-
- byte[] result = new byte[hex.length() / 2];
- for (int i = 0; i < result.length; i++) {
- int d1 = decodeHexDigit(hex.charAt(i * 2)) << 4;
- int d2 = decodeHexDigit(hex.charAt(i * 2 + 1));
- result[i] = (byte) (d1 + d2);
- }
- return of(result);
- }
-
- private static int decodeHexDigit(char c) {
- if (c >= '0' && c <= '9') return c - '0';
- if (c >= 'a' && c <= 'f') return c - 'a' + 10;
- if (c >= 'A' && c <= 'F') return c - 'A' + 10;
- throw new IllegalArgumentException("Unexpected hex digit: " + c);
- }
-
- /**
- * Reads {@code count} bytes from {@code in} and returns the result.
- *
- * @throws java.io.EOFException if {@code in} has fewer than {@code count}
- * bytes to read.
- */
- public static ByteString read(InputStream in, int byteCount) throws IOException {
- if (in == null) throw new IllegalArgumentException("in == null");
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
-
- byte[] result = new byte[byteCount];
- for (int offset = 0, read; offset < byteCount; offset += read) {
- read = in.read(result, offset, byteCount - offset);
- if (read == -1) throw new EOFException();
- }
- return new ByteString(result);
- }
-
- /**
- * Returns a byte string equal to this byte string, but with the bytes 'A'
- * through 'Z' replaced with the corresponding byte in 'a' through 'z'.
- * Returns this byte string if it contains no bytes in 'A' through 'Z'.
- */
- public ByteString toAsciiLowercase() {
- // Search for an uppercase character. If we don't find one, return this.
- for (int i = 0; i < data.length; i++) {
- byte c = data[i];
- if (c < 'A' || c > 'Z') continue;
-
- // If we reach this point, this string is not not lowercase. Create and
- // return a new byte string.
- byte[] lowercase = data.clone();
- lowercase[i++] = (byte) (c - ('A' - 'a'));
- for (; i < lowercase.length; i++) {
- c = lowercase[i];
- if (c < 'A' || c > 'Z') continue;
- lowercase[i] = (byte) (c - ('A' - 'a'));
- }
- return new ByteString(lowercase);
- }
- return this;
- }
-
- /**
- * Returns a byte string equal to this byte string, but with the bytes 'a'
- * through 'z' replaced with the corresponding byte in 'A' through 'Z'.
- * Returns this byte string if it contains no bytes in 'a' through 'z'.
- */
- public ByteString toAsciiUppercase() {
- // Search for an lowercase character. If we don't find one, return this.
- for (int i = 0; i < data.length; i++) {
- byte c = data[i];
- if (c < 'a' || c > 'z') continue;
-
- // If we reach this point, this string is not not uppercase. Create and
- // return a new byte string.
- byte[] lowercase = data.clone();
- lowercase[i++] = (byte) (c - ('a' - 'A'));
- for (; i < lowercase.length; i++) {
- c = lowercase[i];
- if (c < 'a' || c > 'z') continue;
- lowercase[i] = (byte) (c - ('a' - 'A'));
- }
- return new ByteString(lowercase);
- }
- return this;
- }
-
- /**
- * Returns the byte at {@code pos}.
- */
- public byte getByte(int pos) {
- return data[pos];
- }
-
- /**
- * Returns the number of bytes in this ByteString.
- */
- public int size() {
- return data.length;
- }
-
- /**
- * Returns a byte array containing a copy of the bytes in this {@code ByteString}.
- */
- public byte[] toByteArray() {
- return data.clone();
- }
-
- /**
- * Writes the contents of this byte string to {@code out}.
- */
- public void write(OutputStream out) throws IOException {
- if (out == null) throw new IllegalArgumentException("out == null");
- out.write(data);
- }
-
- @Override
- public boolean equals(Object o) {
- return o == this || o instanceof ByteString && Arrays.equals(((ByteString) o).data, data);
- }
-
- @Override
- public int hashCode() {
- int result = hashCode;
- return result != 0 ? result : (hashCode = Arrays.hashCode(data));
- }
-
- @Override
- public String toString() {
- if (data.length == 0) {
- return "ByteString[size=0]";
- }
-
- if (data.length <= 16) {
- return String.format("ByteString[size=%s data=%s]", data.length, hex());
- }
-
- try {
- return String.format("ByteString[size=%s md5=%s]", data.length,
- ByteString.of(MessageDigest.getInstance("MD5").digest(data)).hex());
- } catch (NoSuchAlgorithmException e) {
- throw new AssertionError();
- }
- }
-
- private void readObject(ObjectInputStream in) throws IOException {
- int dataLength = in.readInt();
- ByteString byteString = ByteString.read(in, dataLength);
- try {
- Field field = ByteString.class.getDeclaredField("data");
- field.setAccessible(true);
- field.set(this, byteString.data);
- } catch (NoSuchFieldException e) {
- throw new AssertionError();
- } catch (IllegalAccessException e) {
- throw new AssertionError();
- }
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException {
- out.writeInt(data.length);
- out.write(data);
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/DeflaterSink.java b/contentstack/src/main/java/com/contentstack/okio/DeflaterSink.java
deleted file mode 100755
index 22e541ec..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/DeflaterSink.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import android.annotation.SuppressLint;
-
-import java.io.IOException;
-import java.util.zip.Deflater;
-
-/**
- * A sink that uses DEFLATE to
- * compress data written to another source.
- *
- * This is equivalent to using {@link Deflater} with the sync flush option.
- * This class does not offer any partial flush mechanism. For best performance,
- * only call {@link #flush} when application behavior requires it.
- */
-public final class DeflaterSink implements Sink {
- private final BufferedSink sink;
- private final Deflater deflater;
- private boolean closed;
-
- public DeflaterSink(Sink sink, Deflater deflater) {
- this(Okio.buffer(sink), deflater);
- }
-
- /**
- * This package-private constructor shares a buffer with its trusted caller.
- * In general we can't share a BufferedSource because the deflater holds input
- * bytes until they are inflated.
- */
- DeflaterSink(BufferedSink sink, Deflater deflater) {
- if (sink == null) throw new IllegalArgumentException("source == null");
- if (deflater == null) throw new IllegalArgumentException("inflater == null");
- this.sink = sink;
- this.deflater = deflater;
- }
-
- @Override
- public void write(Buffer source, long byteCount)
- throws IOException {
- Util.checkOffsetAndCount(source.size, 0, byteCount);
- while (byteCount > 0) {
- // Share bytes from the head segment of 'source' with the deflater.
- Segment head = source.head;
- int toDeflate = (int) Math.min(byteCount, head.limit - head.pos);
- deflater.setInput(head.data, head.pos, toDeflate);
-
- // Deflate those bytes into sink.
- deflate(false);
-
- // Mark those bytes as read.
- source.size -= toDeflate;
- head.pos += toDeflate;
- if (head.pos == head.limit) {
- source.head = head.pop();
- SegmentPool.INSTANCE.recycle(head);
- }
-
- byteCount -= toDeflate;
- }
- }
-
- @SuppressLint("NewApi")
- private void deflate(boolean syncFlush) throws IOException {
- Buffer buffer = sink.buffer();
- while (true) {
- Segment s = buffer.writableSegment(1);
-
- // The 4-parameter overload of deflate() doesn't exist in the RI until
- // Java 1.7, and is public (although with @hide) on Android since 2.3.
- // The @hide tag means that this code won't compile against the Android
- // 2.3 SDK, but it will run fine there.
- int deflated = syncFlush
- ? deflater.deflate(s.data, s.limit, Segment.SIZE - s.limit/*, Deflater.SYNC_FLUSH*/)
- : deflater.deflate(s.data, s.limit, Segment.SIZE - s.limit);
-
- if (deflated > 0) {
- s.limit += deflated;
- buffer.size += deflated;
- sink.emitCompleteSegments();
- } else if (deflater.needsInput()) {
- return;
- }
- }
- }
-
- @Override
- public void flush() throws IOException {
- deflate(true);
- sink.flush();
- }
-
- void finishDeflate() throws IOException {
- deflater.finish();
- deflate(false);
- }
-
- @Override
- public void close() throws IOException {
- if (closed) return;
-
- // Emit deflated data to the underlying sink. If this fails, we still need
- // to close the deflater and the sink; otherwise we risk leaking resources.
- Throwable thrown = null;
- try {
- finishDeflate();
- } catch (Throwable e) {
- thrown = e;
- }
-
- try {
- deflater.end();
- } catch (Throwable e) {
- if (thrown == null) thrown = e;
- }
-
- try {
- sink.close();
- } catch (Throwable e) {
- if (thrown == null) thrown = e;
- }
- closed = true;
-
- if (thrown != null) Util.sneakyRethrow(thrown);
- }
-
- @Override
- public Timeout timeout() {
- return sink.timeout();
- }
-
- @Override
- public String toString() {
- return "DeflaterSink(" + sink + ")";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/ForwardingSink.java b/contentstack/src/main/java/com/contentstack/okio/ForwardingSink.java
deleted file mode 100755
index f57cda51..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/ForwardingSink.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.IOException;
-
-/**
- * A {@link Sink} which forwards calls to another. Useful for subclassing.
- */
-public abstract class ForwardingSink implements Sink {
- private final Sink delegate;
-
- public ForwardingSink(Sink delegate) {
- if (delegate == null) throw new IllegalArgumentException("delegate == null");
- this.delegate = delegate;
- }
-
- /**
- * {@link Sink} to which this instance is delegating.
- */
- public final Sink delegate() {
- return delegate;
- }
-
- @Override
- public void write(Buffer source, long byteCount) throws IOException {
- delegate.write(source, byteCount);
- }
-
- @Override
- public void flush() throws IOException {
- delegate.flush();
- }
-
- @Override
- public Timeout timeout() {
- return delegate.timeout();
- }
-
- @Override
- public void close() throws IOException {
- delegate.close();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "(" + delegate.toString() + ")";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/ForwardingSource.java b/contentstack/src/main/java/com/contentstack/okio/ForwardingSource.java
deleted file mode 100755
index b11251df..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/ForwardingSource.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.IOException;
-
-/**
- * A {@link Source} which forwards calls to another. Useful for subclassing.
- */
-public abstract class ForwardingSource implements Source {
- private final Source delegate;
-
- public ForwardingSource(Source delegate) {
- if (delegate == null) throw new IllegalArgumentException("delegate == null");
- this.delegate = delegate;
- }
-
- /**
- * {@link Source} to which this instance is delegating.
- */
- public final Source delegate() {
- return delegate;
- }
-
- @Override
- public long read(Buffer sink, long byteCount) throws IOException {
- return delegate.read(sink, byteCount);
- }
-
- @Override
- public Timeout timeout() {
- return delegate.timeout();
- }
-
- @Override
- public void close() throws IOException {
- delegate.close();
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "(" + delegate.toString() + ")";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/GzipSink.java b/contentstack/src/main/java/com/contentstack/okio/GzipSink.java
deleted file mode 100755
index 90d6b34c..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/GzipSink.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.IOException;
-import java.util.zip.CRC32;
-import java.util.zip.Deflater;
-
-import static java.util.zip.Deflater.DEFAULT_COMPRESSION;
-
-/**
- * A sink that uses GZIP to
- * compress written data to another sink.
- *
- * This is equivalent to using {@link Deflater} with the sync flush option.
- * This class does not offer any partial flush mechanism. For best performance,
- * only call {@link #flush} when application behavior requires it.
- */
-public final class GzipSink implements Sink {
- /**
- * Sink into which the GZIP format is written.
- */
- private final BufferedSink sink;
-
- /**
- * The deflater used to compress the body.
- */
- private final Deflater deflater;
-
- /**
- * The deflater sink takes care of moving data between decompressed source and
- * compressed sink buffers.
- */
- private final DeflaterSink deflaterSink;
-
- private boolean closed;
-
- /**
- * Checksum calculated for the compressed body.
- */
- private final CRC32 crc = new CRC32();
-
- public GzipSink(Sink sink) {
- if (sink == null) throw new IllegalArgumentException("sink == null");
- this.deflater = new Deflater(DEFAULT_COMPRESSION, true /* No wrap */);
- this.sink = Okio.buffer(sink);
- this.deflaterSink = new DeflaterSink(this.sink, deflater);
-
- writeHeader();
- }
-
- @Override
- public void write(Buffer source, long byteCount) throws IOException {
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (byteCount == 0) return;
-
- updateCrc(source, byteCount);
- deflaterSink.write(source, byteCount);
- }
-
- @Override
- public void flush() throws IOException {
- deflaterSink.flush();
- }
-
- @Override
- public Timeout timeout() {
- return sink.timeout();
- }
-
- @Override
- public void close() throws IOException {
- if (closed) return;
-
- // This method delegates to the DeflaterSink for finishing the deflate process
- // but keeps responsibility for releasing the deflater's resources. This is
- // necessary because writeFooter needs to query the proccessed byte count which
- // only works when the defalter is still open.
-
- Throwable thrown = null;
- try {
- deflaterSink.finishDeflate();
- writeFooter();
- } catch (Throwable e) {
- thrown = e;
- }
-
- try {
- deflater.end();
- } catch (Throwable e) {
- if (thrown == null) thrown = e;
- }
-
- try {
- sink.close();
- } catch (Throwable e) {
- if (thrown == null) thrown = e;
- }
- closed = true;
-
- if (thrown != null) Util.sneakyRethrow(thrown);
- }
-
- private void writeHeader() {
- // Write the Gzip header directly into the buffer for the sink to avoid handling IOException.
- Buffer buffer = this.sink.buffer();
- buffer.writeShort(0x1f8b); // Two-byte Gzip ID.
- buffer.writeByte(0x08); // 8 == Deflate compression method.
- buffer.writeByte(0x00); // No flags.
- buffer.writeInt(0x00); // No modification time.
- buffer.writeByte(0x00); // No extra flags.
- buffer.writeByte(0x00); // No OS.
- }
-
- private void writeFooter() throws IOException {
- sink.writeIntLe((int) crc.getValue()); // CRC of original data.
- sink.writeIntLe(deflater.getTotalIn()); // Length of original data.
- }
-
- /**
- * Updates the CRC with the given bytes.
- */
- private void updateCrc(Buffer buffer, long byteCount) {
- for (Segment head = buffer.head; byteCount > 0; head = head.next) {
- int segmentLength = (int) Math.min(byteCount, head.limit - head.pos);
- crc.update(head.data, head.pos, segmentLength);
- byteCount -= segmentLength;
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/GzipSource.java b/contentstack/src/main/java/com/contentstack/okio/GzipSource.java
deleted file mode 100755
index 57e3089b..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/GzipSource.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.zip.CRC32;
-import java.util.zip.Inflater;
-
-/**
- * A source that uses GZIP to
- * decompress data read from another source.
- */
-public final class GzipSource implements Source {
- private static final byte FHCRC = 1;
- private static final byte FEXTRA = 2;
- private static final byte FNAME = 3;
- private static final byte FCOMMENT = 4;
-
- private static final byte SECTION_HEADER = 0;
- private static final byte SECTION_BODY = 1;
- private static final byte SECTION_TRAILER = 2;
- private static final byte SECTION_DONE = 3;
-
- /**
- * The current section. Always progresses forward.
- */
- private int section = SECTION_HEADER;
-
- /**
- * Our source should yield a GZIP header (which we consume directly), followed
- * by deflated bytes (which we consume via an InflaterSource), followed by a
- * GZIP trailer (which we also consume directly).
- */
- private final BufferedSource source;
-
- /**
- * The inflater used to decompress the deflated body.
- */
- private final Inflater inflater;
-
- /**
- * The inflater source takes care of moving data between compressed source and
- * decompressed sink buffers.
- */
- private final InflaterSource inflaterSource;
-
- /**
- * Checksum used to check both the GZIP header and decompressed body.
- */
- private final CRC32 crc = new CRC32();
-
- public GzipSource(Source source) {
- if (source == null) throw new IllegalArgumentException("source == null");
- this.inflater = new Inflater(true);
- this.source = Okio.buffer(source);
- this.inflaterSource = new InflaterSource(this.source, inflater);
- }
-
- @Override
- public long read(Buffer sink, long byteCount) throws IOException {
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (byteCount == 0) return 0;
-
- // If we haven't consumed the header, we must consume it before anything else.
- if (section == SECTION_HEADER) {
- consumeHeader();
- section = SECTION_BODY;
- }
-
- // Attempt to read at least a byte of the body. If we do, we're done.
- if (section == SECTION_BODY) {
- long offset = sink.size;
- long result = inflaterSource.read(sink, byteCount);
- if (result != -1) {
- updateCrc(sink, offset, result);
- return result;
- }
- section = SECTION_TRAILER;
- }
-
- // The body is exhausted; time to read the trailer. We always consume the
- // trailer before returning a -1 exhausted result; that way if you read to
- // the end of a GzipSource you guarantee that the CRC has been checked.
- if (section == SECTION_TRAILER) {
- consumeTrailer();
- section = SECTION_DONE;
-
- // Gzip streams self-terminate: they return -1 before their underlying
- // source returns -1. Here we attempt to force the underlying stream to
- // return -1 which may trigger it to release its resources. If it doesn't
- // return -1, then our Gzip data finished prematurely!
- if (!source.exhausted()) {
- throw new IOException("gzip finished without exhausting source");
- }
- }
-
- return -1;
- }
-
- private void consumeHeader() throws IOException {
- // Read the 10-byte header. We peek at the flags byte first so we know if we
- // need to CRC the entire header. Then we read the magic ID1ID2 sequence.
- // We can skip everything else in the first 10 bytes.
- // +---+---+---+---+---+---+---+---+---+---+
- // |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
- // +---+---+---+---+---+---+---+---+---+---+
- source.require(10);
- byte flags = source.buffer().getByte(3);
- boolean fhcrc = ((flags >> FHCRC) & 1) == 1;
- if (fhcrc) updateCrc(source.buffer(), 0, 10);
-
- short id1id2 = source.readShort();
- checkEqual("ID1ID2", (short) 0x1f8b, id1id2);
- source.skip(8);
-
- // Skip optional extra fields.
- // +---+---+=================================+
- // | XLEN |...XLEN bytes of "extra field"...| (more-->)
- // +---+---+=================================+
- if (((flags >> FEXTRA) & 1) == 1) {
- source.require(2);
- if (fhcrc) updateCrc(source.buffer(), 0, 2);
- int xlen = source.buffer().readShortLe();
- source.require(xlen);
- if (fhcrc) updateCrc(source.buffer(), 0, xlen);
- source.skip(xlen);
- }
-
- // Skip an optional 0-terminated name.
- // +=========================================+
- // |...original file name, zero-terminated...| (more-->)
- // +=========================================+
- if (((flags >> FNAME) & 1) == 1) {
- long index = source.indexOf((byte) 0);
- if (index == -1) throw new EOFException();
- if (fhcrc) updateCrc(source.buffer(), 0, index + 1);
- source.skip(index + 1);
- }
-
- // Skip an optional 0-terminated comment.
- // +===================================+
- // |...file comment, zero-terminated...| (more-->)
- // +===================================+
- if (((flags >> FCOMMENT) & 1) == 1) {
- long index = source.indexOf((byte) 0);
- if (index == -1) throw new EOFException();
- if (fhcrc) updateCrc(source.buffer(), 0, index + 1);
- source.skip(index + 1);
- }
-
- // Confirm the optional header CRC.
- // +---+---+
- // | CRC16 |
- // +---+---+
- if (fhcrc) {
- checkEqual("FHCRC", source.readShortLe(), (short) crc.getValue());
- crc.reset();
- }
- }
-
- private void consumeTrailer() throws IOException {
- // Read the eight-byte trailer. Confirm the body's CRC and size.
- // +---+---+---+---+---+---+---+---+
- // | CRC32 | ISIZE |
- // +---+---+---+---+---+---+---+---+
- checkEqual("CRC", source.readIntLe(), (int) crc.getValue());
- checkEqual("ISIZE", source.readIntLe(), inflater.getTotalOut());
- }
-
- @Override
- public Timeout timeout() {
- return source.timeout();
- }
-
- @Override
- public void close() throws IOException {
- inflaterSource.close();
- }
-
- /**
- * Updates the CRC with the given bytes.
- */
- private void updateCrc(Buffer buffer, long offset, long byteCount) {
- // Skip segments that we aren't checksumming.
- Segment s = buffer.head;
- for (; offset >= (s.limit - s.pos); s = s.next) {
- offset -= (s.limit - s.pos);
- }
-
- // Checksum one segment at a time.
- for (; byteCount > 0; s = s.next) {
- int pos = (int) (s.pos + offset);
- int toUpdate = (int) Math.min(s.limit - pos, byteCount);
- crc.update(s.data, pos, toUpdate);
- byteCount -= toUpdate;
- offset = 0;
- }
- }
-
- private void checkEqual(String name, int expected, int actual) throws IOException {
- if (actual != expected) {
- throw new IOException(String.format(
- "%s: actual 0x%08x != expected 0x%08x", name, actual, expected));
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/InflaterSource.java b/contentstack/src/main/java/com/contentstack/okio/InflaterSource.java
deleted file mode 100755
index c04d0d9d..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/InflaterSource.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.zip.DataFormatException;
-import java.util.zip.Inflater;
-
-/**
- * A source that uses DEFLATE
- * to decompress data read from another source.
- */
-public final class InflaterSource implements Source {
- private final BufferedSource source;
- private final Inflater inflater;
-
- /**
- * When we call Inflater.setInput(), the inflater keeps our byte array until
- * it needs input again. This tracks how many bytes the inflater is currently
- * holding on to.
- */
- private int bufferBytesHeldByInflater;
- private boolean closed;
-
- public InflaterSource(Source source, Inflater inflater) {
- this(Okio.buffer(source), inflater);
- }
-
- /**
- * This package-private constructor shares a buffer with its trusted caller.
- * In general we can't share a BufferedSource because the inflater holds input
- * bytes until they are inflated.
- */
- InflaterSource(BufferedSource source, Inflater inflater) {
- if (source == null) throw new IllegalArgumentException("source == null");
- if (inflater == null) throw new IllegalArgumentException("inflater == null");
- this.source = source;
- this.inflater = inflater;
- }
-
- @Override
- public long read(
- Buffer sink, long byteCount) throws IOException {
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (closed) throw new IllegalStateException("closed");
- if (byteCount == 0) return 0;
-
- while (true) {
- boolean sourceExhausted = refill();
-
- // Decompress the inflater's compressed data into the sink.
- try {
- Segment tail = sink.writableSegment(1);
- int bytesInflated = inflater.inflate(tail.data, tail.limit, Segment.SIZE - tail.limit);
- if (bytesInflated > 0) {
- tail.limit += bytesInflated;
- sink.size += bytesInflated;
- return bytesInflated;
- }
- if (inflater.finished() || inflater.needsDictionary()) {
- releaseInflatedBytes();
- return -1;
- }
- if (sourceExhausted) throw new EOFException("source exhausted prematurely");
- } catch (DataFormatException e) {
- throw new IOException(e);
- }
- }
- }
-
- /**
- * Refills the inflater with compressed data if it needs input. (And only if
- * it needs input). Returns true if the inflater required input but the source
- * was exhausted.
- */
- public boolean refill() throws IOException {
- if (!inflater.needsInput()) return false;
-
- releaseInflatedBytes();
- if (inflater.getRemaining() != 0) throw new IllegalStateException("?");
-
- // If there are compressed bytes in the source, assign them to the inflater.
- if (source.exhausted()) return true;
-
- // Assign buffer bytes to the inflater.
- Segment head = source.buffer().head;
- bufferBytesHeldByInflater = head.limit - head.pos;
- inflater.setInput(head.data, head.pos, bufferBytesHeldByInflater);
- return false;
- }
-
- /**
- * When the inflater has processed compressed data, remove it from the buffer.
- */
- private void releaseInflatedBytes() throws IOException {
- if (bufferBytesHeldByInflater == 0) return;
- int toRelease = bufferBytesHeldByInflater - inflater.getRemaining();
- bufferBytesHeldByInflater -= toRelease;
- source.skip(toRelease);
- }
-
- @Override
- public Timeout timeout() {
- return source.timeout();
- }
-
- @Override
- public void close() throws IOException {
- if (closed) return;
- inflater.end();
- closed = true;
- source.close();
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Okio.java b/contentstack/src/main/java/com/contentstack/okio/Okio.java
deleted file mode 100755
index 8014efc5..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Okio.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static com.contentstack.okio.Util.checkOffsetAndCount;
-
-/**
- * Essential APIs for working with Okio.
- */
-public final class Okio {
- private static final Logger logger = Logger.getLogger(Okio.class.getName());
-
- private Okio() {
- }
-
- /**
- * Returns a new source that buffers reads from {@code source}. The returned
- * source will perform bulk reads into its in-memory buffer. Use this wherever
- * you read a source to get an ergonomic and efficient access to data.
- */
- public static BufferedSource buffer(Source source) {
- if (source == null) throw new IllegalArgumentException("source == null");
- return new RealBufferedSource(source);
- }
-
- /**
- * Returns a new sink that buffers writes to {@code sink}. The returned sink
- * will batch writes to {@code sink}. Use this wherever you write to a sink to
- * get an ergonomic and efficient access to data.
- */
- public static BufferedSink buffer(Sink sink) {
- if (sink == null) throw new IllegalArgumentException("sink == null");
- return new RealBufferedSink(sink);
- }
-
- /**
- * Returns a sink that writes to {@code out}.
- */
- public static Sink sink(final OutputStream out) {
- return sink(out, new Timeout());
- }
-
- private static Sink sink(final OutputStream out, final Timeout timeout) {
- if (out == null) throw new IllegalArgumentException("out == null");
- if (timeout == null) throw new IllegalArgumentException("timeout == null");
-
- return new Sink() {
- @Override
- public void write(Buffer source, long byteCount) throws IOException {
- checkOffsetAndCount(source.size, 0, byteCount);
- while (byteCount > 0) {
- timeout.throwIfReached();
- Segment head = source.head;
- int toCopy = (int) Math.min(byteCount, head.limit - head.pos);
- out.write(head.data, head.pos, toCopy);
-
- head.pos += toCopy;
- byteCount -= toCopy;
- source.size -= toCopy;
-
- if (head.pos == head.limit) {
- source.head = head.pop();
- SegmentPool.INSTANCE.recycle(head);
- }
- }
- }
-
- @Override
- public void flush() throws IOException {
- out.flush();
- }
-
- @Override
- public void close() throws IOException {
- out.close();
- }
-
- @Override
- public Timeout timeout() {
- return timeout;
- }
-
- @Override
- public String toString() {
- return "sink(" + out + ")";
- }
- };
- }
-
- /**
- * Returns a sink that writes to {@code socket}. Prefer this over {@link
- * #sink(OutputStream)} because this method honors timeouts. When the socket
- * write times out, the socket is asynchronously closed by a watchdog thread.
- */
- public static Sink sink(final Socket socket) throws IOException {
- if (socket == null) throw new IllegalArgumentException("socket == null");
- AsyncTimeout timeout = timeout(socket);
- Sink sink = sink(socket.getOutputStream(), timeout);
- return timeout.sink(sink);
- }
-
- /**
- * Returns a source that reads from {@code in}.
- */
- public static Source source(final InputStream in) {
- return source(in, new Timeout());
- }
-
- private static Source source(final InputStream in, final Timeout timeout) {
- if (in == null) throw new IllegalArgumentException("in == null");
- if (timeout == null) throw new IllegalArgumentException("timeout == null");
-
- return new Source() {
- @Override
- public long read(Buffer sink, long byteCount) throws IOException {
- if (byteCount < 0)
- throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- timeout.throwIfReached();
- Segment tail = sink.writableSegment(1);
- int maxToCopy = (int) Math.min(byteCount, Segment.SIZE - tail.limit);
- int bytesRead = in.read(tail.data, tail.limit, maxToCopy);
- if (bytesRead == -1) return -1;
- tail.limit += bytesRead;
- sink.size += bytesRead;
- return bytesRead;
- }
-
- @Override
- public void close() throws IOException {
- in.close();
- }
-
- @Override
- public Timeout timeout() {
- return timeout;
- }
-
- @Override
- public String toString() {
- return "source(" + in + ")";
- }
- };
- }
-
- /**
- * Returns a source that reads from {@code file}.
- */
- public static Source source(File file) throws FileNotFoundException {
- if (file == null) throw new IllegalArgumentException("file == null");
- return source(new FileInputStream(file));
- }
-
- /** Returns a source that reads from {@code path}. */
- // Should only be invoked on Java 7+.
- /*public static Source source(android.graphics.Path path, OpenOption... options) throws IOException {
- if (path == null) throw new IllegalArgumentException("path == null");
- return source(android.provider.MediaStore.Files.newInputStream(path, options));
- }*/
-
- /**
- * Returns a sink that writes to {@code file}.
- */
- public static Sink sink(File file) throws FileNotFoundException {
- if (file == null) throw new IllegalArgumentException("file == null");
- return sink(new FileOutputStream(file));
- }
-
- /**
- * Returns a sink that appends to {@code file}.
- */
- public static Sink appendingSink(File file) throws FileNotFoundException {
- if (file == null) throw new IllegalArgumentException("file == null");
- return sink(new FileOutputStream(file, true));
- }
-
- /** Returns a sink that writes to {@code path}. */// Should only be invoked on Java 7+.
- /* public static Sink sink(android.graphics.Path path, OpenOption... options) throws IOException {
- if (path == null) throw new IllegalArgumentException("path == null");
- return sink(android.provider.MediaStore.Files.newOutputStream(path, options));
- }*/
-
- /**
- * Returns a source that reads from {@code socket}. Prefer this over {@link
- * #source(InputStream)} because this method honors timeouts. When the socket
- * read times out, the socket is asynchronously closed by a watchdog thread.
- */
- public static Source source(final Socket socket) throws IOException {
- if (socket == null) throw new IllegalArgumentException("socket == null");
- AsyncTimeout timeout = timeout(socket);
- Source source = source(socket.getInputStream(), timeout);
- return timeout.source(source);
- }
-
- private static AsyncTimeout timeout(final Socket socket) {
- return new AsyncTimeout() {
- @Override
- protected void timedOut() {
- try {
- socket.close();
- } catch (Exception e) {
- logger.log(Level.WARNING, "Failed to close timed out socket " + socket, e);
- }
- }
- };
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/RealBufferedSink.java b/contentstack/src/main/java/com/contentstack/okio/RealBufferedSink.java
deleted file mode 100755
index f151b965..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/RealBufferedSink.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-
-final class RealBufferedSink implements BufferedSink {
- public final Buffer buffer;
- public final Sink sink;
- private boolean closed;
-
- public RealBufferedSink(Sink sink, Buffer buffer) {
- if (sink == null) throw new IllegalArgumentException("sink == null");
- this.buffer = buffer;
- this.sink = sink;
- }
-
- public RealBufferedSink(Sink sink) {
- this(sink, new Buffer());
- }
-
- @Override
- public Buffer buffer() {
- return buffer;
- }
-
- @Override
- public void write(Buffer source, long byteCount)
- throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.write(source, byteCount);
- emitCompleteSegments();
- }
-
- @Override
- public BufferedSink write(ByteString byteString) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.write(byteString);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeUtf8(String string) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeUtf8(string);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeString(String string, Charset charset) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeString(string, charset);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink write(byte[] source) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.write(source);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink write(byte[] source, int offset, int byteCount) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.write(source, offset, byteCount);
- return emitCompleteSegments();
- }
-
- @Override
- public long writeAll(Source source) throws IOException {
- if (source == null) throw new IllegalArgumentException("source == null");
- long totalBytesRead = 0;
- for (long readCount; (readCount = source.read(buffer, Segment.SIZE)) != -1; ) {
- totalBytesRead += readCount;
- emitCompleteSegments();
- }
- return totalBytesRead;
- }
-
- @Override
- public BufferedSink writeByte(int b) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeByte(b);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeShort(int s) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeShort(s);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeShortLe(int s) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeShortLe(s);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeInt(int i) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeInt(i);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeIntLe(int i) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeIntLe(i);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeLong(long v) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeLong(v);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink writeLongLe(long v) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- buffer.writeLongLe(v);
- return emitCompleteSegments();
- }
-
- @Override
- public BufferedSink emitCompleteSegments() throws IOException {
- if (closed) throw new IllegalStateException("closed");
- long byteCount = buffer.completeSegmentByteCount();
- if (byteCount > 0) sink.write(buffer, byteCount);
- return this;
- }
-
- @Override
- public OutputStream outputStream() {
- return new OutputStream() {
- @Override
- public void write(int b) throws IOException {
- if (closed) throw new IOException("closed");
- buffer.writeByte((byte) b);
- emitCompleteSegments();
- }
-
- @Override
- public void write(byte[] data, int offset, int byteCount) throws IOException {
- if (closed) throw new IOException("closed");
- buffer.write(data, offset, byteCount);
- emitCompleteSegments();
- }
-
- @Override
- public void flush() throws IOException {
- // For backwards compatibility, a flush() on a closed stream is a no-op.
- if (!closed) {
- RealBufferedSink.this.flush();
- }
- }
-
- @Override
- public void close() throws IOException {
- RealBufferedSink.this.close();
- }
-
- @Override
- public String toString() {
- return RealBufferedSink.this + ".outputStream()";
- }
- };
- }
-
- @Override
- public void flush() throws IOException {
- if (closed) throw new IllegalStateException("closed");
- if (buffer.size > 0) {
- sink.write(buffer, buffer.size);
- }
- sink.flush();
- }
-
- @Override
- public void close() throws IOException {
- if (closed) return;
-
- // Emit buffered data to the underlying sink. If this fails, we still need
- // to close the sink; otherwise we risk leaking resources.
- Throwable thrown = null;
- try {
- if (buffer.size > 0) {
- sink.write(buffer, buffer.size);
- }
- } catch (Throwable e) {
- thrown = e;
- }
-
- try {
- sink.close();
- } catch (Throwable e) {
- if (thrown == null) thrown = e;
- }
- closed = true;
-
- if (thrown != null) Util.sneakyRethrow(thrown);
- }
-
- @Override
- public Timeout timeout() {
- return sink.timeout();
- }
-
- @Override
- public String toString() {
- return "buffer(" + sink + ")";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/RealBufferedSource.java b/contentstack/src/main/java/com/contentstack/okio/RealBufferedSource.java
deleted file mode 100755
index c8d73bfb..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/RealBufferedSource.java
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
-final class RealBufferedSource implements BufferedSource {
- public final Buffer buffer;
- public final Source source;
- private boolean closed;
-
- public RealBufferedSource(Source source, Buffer buffer) {
- if (source == null) throw new IllegalArgumentException("source == null");
- this.buffer = buffer;
- this.source = source;
- }
-
- public RealBufferedSource(Source source) {
- this(source, new Buffer());
- }
-
- @Override
- public Buffer buffer() {
- return buffer;
- }
-
- @Override
- public long read(Buffer sink, long byteCount) throws IOException {
- if (sink == null) throw new IllegalArgumentException("sink == null");
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (closed) throw new IllegalStateException("closed");
-
- if (buffer.size == 0) {
- long read = source.read(buffer, Segment.SIZE);
- if (read == -1) return -1;
- }
-
- long toRead = Math.min(byteCount, buffer.size);
- return buffer.read(sink, toRead);
- }
-
- @Override
- public boolean exhausted() throws IOException {
- if (closed) throw new IllegalStateException("closed");
- return buffer.exhausted() && source.read(buffer, Segment.SIZE) == -1;
- }
-
- @Override
- public void require(long byteCount) throws IOException {
- if (!request(byteCount)) throw new EOFException();
- }
-
- @Override
- public boolean request(long byteCount) throws IOException {
- if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
- if (closed) throw new IllegalStateException("closed");
- while (buffer.size < byteCount) {
- if (source.read(buffer, Segment.SIZE) == -1) return false;
- }
- return true;
- }
-
- @Override
- public byte readByte() throws IOException {
- require(1);
- return buffer.readByte();
- }
-
- @Override
- public ByteString readByteString() throws IOException {
- buffer.writeAll(source);
- return buffer.readByteString();
- }
-
- @Override
- public ByteString readByteString(long byteCount) throws IOException {
- require(byteCount);
- return buffer.readByteString(byteCount);
- }
-
- @Override
- public byte[] readByteArray() throws IOException {
- buffer.writeAll(source);
- return buffer.readByteArray();
- }
-
- @Override
- public byte[] readByteArray(long byteCount) throws IOException {
- require(byteCount);
- return buffer.readByteArray(byteCount);
- }
-
- @Override
- public int read(byte[] sink) throws IOException {
- return read(sink, 0, sink.length);
- }
-
- @Override
- public void readFully(byte[] sink) throws IOException {
- try {
- require(sink.length);
- } catch (EOFException e) {
- // The underlying source is exhausted. Copy the bytes we got before rethrowing.
- int offset = 0;
- while (buffer.size > 0) {
- int read = buffer.read(sink, offset, (int) buffer.size - offset);
- if (read == -1) throw new AssertionError();
- offset += read;
- }
- throw e;
- }
- buffer.readFully(sink);
- }
-
- @Override
- public int read(byte[] sink, int offset, int byteCount) throws IOException {
- Util.checkOffsetAndCount(sink.length, offset, byteCount);
-
- if (buffer.size == 0) {
- long read = source.read(buffer, Segment.SIZE);
- if (read == -1) return -1;
- }
-
- int toRead = (int) Math.min(byteCount, buffer.size);
- return buffer.read(sink, offset, toRead);
- }
-
- @Override
- public void readFully(Buffer sink, long byteCount) throws IOException {
- try {
- require(byteCount);
- } catch (EOFException e) {
- // The underlying source is exhausted. Copy the bytes we got before rethrowing.
- sink.writeAll(buffer);
- throw e;
- }
- buffer.readFully(sink, byteCount);
- }
-
- @Override
- public long readAll(Sink sink) throws IOException {
- if (sink == null) throw new IllegalArgumentException("sink == null");
-
- long totalBytesWritten = 0;
- while (source.read(buffer, Segment.SIZE) != -1) {
- long emitByteCount = buffer.completeSegmentByteCount();
- if (emitByteCount > 0) {
- totalBytesWritten += emitByteCount;
- sink.write(buffer, emitByteCount);
- }
- }
- if (buffer.size() > 0) {
- totalBytesWritten += buffer.size();
- sink.write(buffer, buffer.size());
- }
- return totalBytesWritten;
- }
-
- @Override
- public String readUtf8() throws IOException {
- buffer.writeAll(source);
- return buffer.readUtf8();
- }
-
- @Override
- public String readUtf8(long byteCount) throws IOException {
- require(byteCount);
- return buffer.readUtf8(byteCount);
- }
-
- @Override
- public String readString(Charset charset) throws IOException {
- if (charset == null) throw new IllegalArgumentException("charset == null");
-
- buffer.writeAll(source);
- return buffer.readString(charset);
- }
-
- @Override
- public String readString(long byteCount, Charset charset) throws IOException {
- require(byteCount);
- if (charset == null) throw new IllegalArgumentException("charset == null");
- return buffer.readString(byteCount, charset);
- }
-
- @Override
- public String readUtf8Line() throws IOException {
- long newline = indexOf((byte) '\n');
-
- if (newline == -1) {
- return buffer.size != 0 ? readUtf8(buffer.size) : null;
- }
-
- return buffer.readUtf8Line(newline);
- }
-
- @Override
- public String readUtf8LineStrict() throws IOException {
- long newline = indexOf((byte) '\n');
- if (newline == -1L) throw new EOFException();
- return buffer.readUtf8Line(newline);
- }
-
- @Override
- public short readShort() throws IOException {
- require(2);
- return buffer.readShort();
- }
-
- @Override
- public short readShortLe() throws IOException {
- require(2);
- return buffer.readShortLe();
- }
-
- @Override
- public int readInt() throws IOException {
- require(4);
- return buffer.readInt();
- }
-
- @Override
- public int readIntLe() throws IOException {
- require(4);
- return buffer.readIntLe();
- }
-
- @Override
- public long readLong() throws IOException {
- require(8);
- return buffer.readLong();
- }
-
- @Override
- public long readLongLe() throws IOException {
- require(8);
- return buffer.readLongLe();
- }
-
- @Override
- public void skip(long byteCount) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- while (byteCount > 0) {
- if (buffer.size == 0 && source.read(buffer, Segment.SIZE) == -1) {
- throw new EOFException();
- }
- long toSkip = Math.min(byteCount, buffer.size());
- buffer.skip(toSkip);
- byteCount -= toSkip;
- }
- }
-
- @Override
- public long indexOf(byte b) throws IOException {
- return indexOf(b, 0);
- }
-
- @Override
- public long indexOf(byte b, long fromIndex) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- while (fromIndex >= buffer.size) {
- if (source.read(buffer, Segment.SIZE) == -1) return -1L;
- }
- long index;
- while ((index = buffer.indexOf(b, fromIndex)) == -1) {
- fromIndex = buffer.size;
- if (source.read(buffer, Segment.SIZE) == -1) return -1L;
- }
- return index;
- }
-
- @Override
- public long indexOfElement(ByteString targetBytes) throws IOException {
- return indexOfElement(targetBytes, 0);
- }
-
- @Override
- public long indexOfElement(ByteString targetBytes, long fromIndex) throws IOException {
- if (closed) throw new IllegalStateException("closed");
- while (fromIndex >= buffer.size) {
- if (source.read(buffer, Segment.SIZE) == -1) return -1L;
- }
- long index;
- while ((index = buffer.indexOfElement(targetBytes, fromIndex)) == -1) {
- fromIndex = buffer.size;
- if (source.read(buffer, Segment.SIZE) == -1) return -1L;
- }
- return index;
- }
-
- @Override
- public InputStream inputStream() {
- return new InputStream() {
- @Override
- public int read() throws IOException {
- if (closed) throw new IOException("closed");
- if (buffer.size == 0) {
- long count = source.read(buffer, Segment.SIZE);
- if (count == -1) return -1;
- }
- return buffer.readByte() & 0xff;
- }
-
- @Override
- public int read(byte[] data, int offset, int byteCount) throws IOException {
- if (closed) throw new IOException("closed");
- Util.checkOffsetAndCount(data.length, offset, byteCount);
-
- if (buffer.size == 0) {
- long count = source.read(buffer, Segment.SIZE);
- if (count == -1) return -1;
- }
-
- return buffer.read(data, offset, byteCount);
- }
-
- @Override
- public int available() throws IOException {
- if (closed) throw new IOException("closed");
- return (int) Math.min(buffer.size, Integer.MAX_VALUE);
- }
-
- @Override
- public void close() throws IOException {
- RealBufferedSource.this.close();
- }
-
- @Override
- public String toString() {
- return RealBufferedSource.this + ".inputStream()";
- }
- };
- }
-
- @Override
- public void close() throws IOException {
- if (closed) return;
- closed = true;
- source.close();
- buffer.clear();
- }
-
- @Override
- public Timeout timeout() {
- return source.timeout();
- }
-
- @Override
- public String toString() {
- return "buffer(" + source + ")";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Segment.java b/contentstack/src/main/java/com/contentstack/okio/Segment.java
deleted file mode 100755
index 6be3aa97..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Segment.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-/**
- * A segment of a buffer.
- *
- * Each segment in a buffer is a circularly-linked list node referencing
- * the following and preceding segments in the buffer.
- *
- * Each segment in the pool is a singly-linked list node referencing the rest
- * of segments in the pool.
- */
-final class Segment {
- static final int SIZE = 2048;
- final byte[] data = new byte[SIZE];
- /**
- * The next byte of application data byte to read in this segment.
- */
- int pos;
-
- /**
- * The first byte of available data ready to be written to.
- */
- int limit;
-
- /**
- * Next segment in a linked or circularly-linked list.
- */
- Segment next;
-
- /**
- * Previous segment in a circularly-linked list.
- */
- Segment prev;
-
- /**
- * Removes this segment of a circularly-linked list and returns its successor.
- * Returns null if the list is now empty.
- */
- public Segment pop() {
- Segment result = next != this ? next : null;
- prev.next = next;
- next.prev = prev;
- next = null;
- prev = null;
- return result;
- }
-
- /**
- * Appends {@code segment} after this segment in the circularly-linked list.
- * Returns the pushed segment.
- */
- public Segment push(Segment segment) {
- segment.prev = this;
- segment.next = next;
- next.prev = segment;
- next = segment;
- return segment;
- }
-
- /**
- * Splits this head of a circularly-linked list into two segments. The first
- * segment contains the data in {@code [pos..pos+byteCount)}. The second
- * segment contains the data in {@code [pos+byteCount..limit)}. This can be
- * useful when moving partial segments from one buffer to another.
- *
- * Returns the new head of the circularly-linked list.
- */
- public Segment split(int byteCount) {
- int aSize = byteCount;
- int bSize = (limit - pos) - byteCount;
- if (aSize <= 0 || bSize <= 0) throw new IllegalArgumentException();
-
- // Which side of the split is larger? We want to copy as few bytes as possible.
- if (aSize < bSize) {
- // Create a segment of size 'aSize' before this segment.
- Segment before = SegmentPool.INSTANCE.take();
- System.arraycopy(data, pos, before.data, before.pos, aSize);
- pos += aSize;
- before.limit += aSize;
- prev.push(before);
- return before;
- } else {
- // Create a new segment of size 'bSize' after this segment.
- Segment after = SegmentPool.INSTANCE.take();
- System.arraycopy(data, pos + aSize, after.data, after.pos, bSize);
- limit -= bSize;
- after.limit += bSize;
- push(after);
- return this;
- }
- }
-
- /**
- * Call this when the tail and its predecessor may both be less than half
- * full. This will copy data so that segments can be recycled.
- */
- public void compact() {
- if (prev == this) throw new IllegalStateException();
- if ((prev.limit - prev.pos) + (limit - pos) > SIZE) return; // Cannot compact.
- writeTo(prev, limit - pos);
- pop();
- SegmentPool.INSTANCE.recycle(this);
- }
-
- public void writeTo(Segment sink, int byteCount) {
- if (byteCount + (sink.limit - sink.pos) > SIZE) throw new IllegalArgumentException();
-
- if (sink.limit + byteCount > SIZE) {
- // We can't fit byteCount bytes at the sink's current position. Compact sink first.
- System.arraycopy(sink.data, sink.pos, sink.data, 0, sink.limit - sink.pos);
- sink.limit -= sink.pos;
- sink.pos = 0;
- }
-
- System.arraycopy(data, pos, sink.data, sink.limit, byteCount);
- sink.limit += byteCount;
- pos += byteCount;
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/SegmentPool.java b/contentstack/src/main/java/com/contentstack/okio/SegmentPool.java
deleted file mode 100755
index f0b6bce2..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/SegmentPool.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-/**
- * A collection of unused segments, necessary to avoid GC churn and zero-fill.
- * This pool is a thread-safe static singleton.
- */
-final class SegmentPool {
- static final SegmentPool INSTANCE = new SegmentPool();
-
- /**
- * The maximum number of bytes to pool.
- */
- static final long MAX_SIZE = 64 * 1024; // 64 KiB.
-
- /**
- * Singly-linked list of segments.
- */
- private Segment next;
-
- /**
- * Total bytes in this pool.
- */
- long byteCount;
-
- private SegmentPool() {
- }
-
- Segment take() {
- synchronized (this) {
- if (next != null) {
- Segment result = next;
- next = result.next;
- result.next = null;
- byteCount -= Segment.SIZE;
- return result;
- }
- }
- return new Segment(); // Pool is empty. Don't zero-fill while holding a lock.
- }
-
- void recycle(Segment segment) {
- if (segment.next != null || segment.prev != null) throw new IllegalArgumentException();
- synchronized (this) {
- if (byteCount + Segment.SIZE > MAX_SIZE) return; // Pool is full.
- byteCount += Segment.SIZE;
- segment.next = next;
- segment.pos = segment.limit = 0;
- next = segment;
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Sink.java b/contentstack/src/main/java/com/contentstack/okio/Sink.java
deleted file mode 100755
index b42afa5d..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Sink.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.Closeable;
-import java.io.IOException;
-
-/**
- * Receives a stream of bytes. Use this interface to write data wherever it's
- * needed: to the network, storage, or a buffer in memory. Sinks may be layered
- * to transform received data, such as to compress, encrypt, throttle, or add
- * protocol framing.
- *
- * Most application code shouldn't operate on a sink directly, but rather
- * {@link BufferedSink} which is both more efficient and more convenient. Use
- * {@link Okio#buffer(Sink)} to wrap any sink with a buffer.
- *
- * Sinks are easy to test: just use an {@link Buffer} in your tests, and
- * read from it to confirm it received the data that was expected.
- *
- * {@code OutputStream} requires multiple layers when emitted data is
- * heterogeneous: a {@code DataOutputStream} for primitive values, a {@code
- * BufferedOutputStream} for buffering, and {@code OutputStreamWriter} for
- * charset encoding. This class uses {@code BufferedSink} for all of the above.
- *
- * Sink is also easier to layer: there is no {@linkplain
- * java.io.OutputStream#write(int) single-byte write} method that is awkward to
- * implement efficiently.
- *
- * Most applications shouldn't operate on a source directly, but rather
- * {@link BufferedSource} which is both more efficient and more convenient. Use
- * {@link Okio#buffer(Source)} to wrap any source with a buffer.
- *
- * Sources are easy to test: just use an {@link Buffer} in your tests, and
- * fill it with the data your application is to read.
- *
- * {@code InputStream} requires multiple layers when consumed data is
- * heterogeneous: a {@code DataInputStream} for primitive values, a {@code
- * BufferedInputStream} for buffering, and {@code InputStreamReader} for
- * strings. This class uses {@code BufferedSource} for all of the above.
- *
- * Source avoids the impossible-to-implement {@linkplain
- * java.io.InputStream#available available()} method. Instead callers specify
- * how many bytes they {@link BufferedSource#require require}.
- *
- * Source omits the unsafe-to-compose {@linkplain java.io.InputStream#mark
- * mark and reset} state that's tracked by {@code InputStream}; callers instead
- * just buffer what they need.
- *
- * When implementing a source, you need not worry about the {@linkplain
- * java.io.InputStream#read single-byte read} method that is awkward to
- * implement efficiently and that returns one of 257 possible values.
- *
- * And source has a stronger {@code skip} method: {@link BufferedSource#skip}
- * won't return prematurely.
- *
- * Timeouts specify the maximum time to wait for a single
- * operation to complete. Timeouts are typically used to detect problems like
- * network partitions. For example, if a remote peer doesn't return any
- * data for ten seconds, we may assume that the peer is unavailable.
- *
- * Deadlines specify the maximum time to spend on a job,
- * composed of one or more operations. Use deadlines to set an upper bound on
- * the time invested on a job. For example, a battery-conscious app may limit
- * how much time it spends preloading content.
- */
-public class Timeout {
- /**
- * An empty timeout that neither tracks nor detects timeouts. Use this when
- * timeouts aren't necessary, such as in implementations whose operations
- * do not block.
- */
- public static final Timeout NONE = new Timeout() {
- @Override
- public Timeout timeout(long timeout, TimeUnit unit) {
- return this;
- }
-
- @Override
- public Timeout deadlineNanoTime(long deadlineNanoTime) {
- return this;
- }
-
- @Override
- public void throwIfReached() throws IOException {
- }
- };
-
- /**
- * True if {@code deadlineNanoTime} is defined. There is no equivalent to null
- * or 0 for {@link System#nanoTime}.
- */
- private boolean hasDeadline;
- private long deadlineNanoTime;
- private long timeoutNanos;
-
- public Timeout() {
- }
-
- /**
- * Wait at most {@code timeout} time before aborting an operation. Using a
- * per-operation timeout means that as long as forward progress is being made,
- * no sequence of operations will fail.
- *
- * If {@code timeout == 0}, operations will run indefinitely. (Operating
- * system timeouts may still apply.)
- */
- public Timeout timeout(long timeout, TimeUnit unit) {
- if (timeout < 0) throw new IllegalArgumentException("timeout < 0: " + timeout);
- if (unit == null) throw new IllegalArgumentException("unit == null");
- this.timeoutNanos = unit.toNanos(timeout);
- return this;
- }
-
- /**
- * Returns the timeout in nanoseconds, or {@code 0} for no timeout.
- */
- public long timeoutNanos() {
- return timeoutNanos;
- }
-
- /**
- * Returns true if a deadline is enabled.
- */
- public boolean hasDeadline() {
- return hasDeadline;
- }
-
- /**
- * Returns the {@linkplain System#nanoTime() nano time} when the deadline will
- * be reached.
- *
- * @throws IllegalStateException if no deadline is set.
- */
- public long deadlineNanoTime() {
- if (!hasDeadline) throw new IllegalStateException("No deadline");
- return deadlineNanoTime;
- }
-
- /**
- * Sets the {@linkplain System#nanoTime() nano time} when the deadline will be
- * reached. All operations must complete before this time. Use a deadline to
- * set a maximum bound on the time spent on a sequence of operations.
- */
- public Timeout deadlineNanoTime(long deadlineNanoTime) {
- this.hasDeadline = true;
- this.deadlineNanoTime = deadlineNanoTime;
- return this;
- }
-
- /**
- * Set a deadline of now plus {@code duration} time.
- */
- public final Timeout deadline(long duration, TimeUnit unit) {
- if (duration <= 0) throw new IllegalArgumentException("duration <= 0: " + duration);
- if (unit == null) throw new IllegalArgumentException("unit == null");
- return deadlineNanoTime(System.nanoTime() + unit.toNanos(duration));
- }
-
- /**
- * Clears the timeout. Operating system timeouts may still apply.
- */
- public Timeout clearTimeout() {
- this.timeoutNanos = 0;
- return this;
- }
-
- /**
- * Clears the deadline.
- */
- public Timeout clearDeadline() {
- this.hasDeadline = false;
- return this;
- }
-
- /**
- * Throws an {@link IOException} if the deadline has been reached or if the
- * current thread has been interrupted. This method doesn't detect timeouts;
- * that should be implemented to asynchronously abort an in-progress
- * operation.
- */
- public void throwIfReached() throws IOException {
- if (Thread.interrupted()) {
- throw new InterruptedIOException();
- }
-
- if (hasDeadline && System.nanoTime() > deadlineNanoTime) {
- throw new IOException("deadline reached");
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Util.java b/contentstack/src/main/java/com/contentstack/okio/Util.java
deleted file mode 100755
index 0f7a3f88..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Util.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-
-final class Util {
- /**
- * A cheap and type-safe constant for the UTF-8 Charset.
- */
- public static final Charset UTF_8 = StandardCharsets.UTF_8;
-
- private Util() {
- }
-
- public static void checkOffsetAndCount(long size, long offset, long byteCount) {
- if ((offset | byteCount) < 0 || offset > size || size - offset < byteCount) {
- throw new ArrayIndexOutOfBoundsException(
- String.format("size=%s offset=%s byteCount=%s", size, offset, byteCount));
- }
- }
-
- public static short reverseBytesShort(short s) {
- int i = s & 0xffff;
- int reversed = (i & 0xff00) >>> 8
- | (i & 0x00ff) << 8;
- return (short) reversed;
- }
-
- public static int reverseBytesInt(int i) {
- return (i & 0xff000000) >>> 24
- | (i & 0x00ff0000) >>> 8
- | (i & 0x0000ff00) << 8
- | (i & 0x000000ff) << 24;
- }
-
- public static long reverseBytesLong(long v) {
- return (v & 0xff00000000000000L) >>> 56
- | (v & 0x00ff000000000000L) >>> 40
- | (v & 0x0000ff0000000000L) >>> 24
- | (v & 0x000000ff00000000L) >>> 8
- | (v & 0x00000000ff000000L) << 8
- | (v & 0x0000000000ff0000L) << 24
- | (v & 0x000000000000ff00L) << 40
- | (v & 0x00000000000000ffL) << 56;
- }
-
- /**
- * Throws {@code t}, even if the declared throws clause doesn't permit it.
- * This is a terrible – but terribly convenient – hack that makes it easy to
- * catch and rethrow exceptions after cleanup. See Java Puzzlers #43.
- */
- public static void sneakyRethrow(Throwable t) {
- Util.
- * This is the default configuration for txtmark's
- * Default safe configuration
- *
- * Default:
- * Default:
- * Default:
- * Default:
- * Default:
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Note: Don't close the HTML tag!
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Note: Don't close the HTML tag!
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Note: Don't close the HTML tag!
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Note: Don't close the HTML tag!
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Default implementation is:
- *
- * Example for a user Decorator having a class attribute on <p> tags.
- * ");
- }
-
- /**
- * @see Decorator#closeParagraph(StringBuilder)
- */
- @Override
- public void closeParagraph(final StringBuilder out) {
- out.append("
- * It also provides methods for processing and analyzing a line.
- *
- * Example usage:
- *
- * Takes care of markdown link references.
- *
- * Usage:
- *
- * The
- * Example:
- * Sync flush
- * Aggressive flushing of this stream may result in reduced compression. Each
- * call to {@link #flush} immediately compresses all currently-buffered data;
- * this early compression may be less effective than compression performed
- * without flushing.
- *
- * Sync flush
- * Aggressive flushing of this stream may result in reduced compression. Each
- * call to {@link #flush} immediately compresses all currently-buffered data;
- * this early compression may be less effective than compression performed
- * without flushing.
- *
- * Comparison with OutputStream
- * This interface is functionally equivalent to {@link java.io.OutputStream}.
- *
- * Interop with OutputStream
- * Use {@link Okio#sink} to adapt an {@code OutputStream} to a sink. Use {@link
- * BufferedSink#outputStream} to adapt a sink to an {@code OutputStream}.
- */
-public interface Sink extends Closeable {
- /**
- * Removes {@code byteCount} bytes from {@code source} and appends them to this.
- */
- void write(Buffer source, long byteCount) throws IOException;
-
- /**
- * Pushes all buffered bytes to their final destination.
- */
- void flush() throws IOException;
-
- /**
- * Returns the timeout for this sink.
- */
- Timeout timeout();
-
- /**
- * Pushes all buffered bytes to their final destination and releases the
- * resources held by this sink. It is an error to write a closed sink. It is
- * safe to close a sink more than once.
- */
- @Override
- void close() throws IOException;
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Source.java b/contentstack/src/main/java/com/contentstack/okio/Source.java
deleted file mode 100755
index a7b6a0bd..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Source.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.Closeable;
-import java.io.IOException;
-
-/**
- * Supplies a stream of bytes. Use this interface to read data from wherever
- * it's located: from the network, storage, or a buffer in memory. Sources may
- * be layered to transform supplied data, such as to decompress, decrypt, or
- * remove protocol framing.
- *
- * Comparison with InputStream
- * This interface is functionally equivalent to {@link java.io.InputStream}.
- *
- * Interop with InputStream
- * Use {@link Okio#source} to adapt an {@code InputStream} to a source. Use
- * {@link BufferedSource#inputStream} to adapt a source to an {@code
- * InputStream}.
- */
-public interface Source extends Closeable {
- /**
- * Removes at least 1, and up to {@code byteCount} bytes from this and appends
- * them to {@code sink}. Returns the number of bytes read, or -1 if this
- * source is exhausted.
- */
- long read(Buffer sink, long byteCount) throws IOException;
-
- /**
- * Returns the timeout for this source.
- */
- Timeout timeout();
-
- /**
- * Closes this source and releases the resources held by this source. It is an
- * error to read a closed source. It is safe to close a source more than once.
- */
- @Override
- void close() throws IOException;
-}
diff --git a/contentstack/src/main/java/com/contentstack/okio/Timeout.java b/contentstack/src/main/java/com/contentstack/okio/Timeout.java
deleted file mode 100755
index cf31c4eb..00000000
--- a/contentstack/src/main/java/com/contentstack/okio/Timeout.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2014 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.contentstack.okio;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A policy on how much time to spend on a task before giving up. When a task
- * times out, it is left in an unspecified state and should be abandoned. For
- * example, if reading from a source times out, that source should be closed and
- * the read should be retried later. If writing to a sink times out, the same
- * rules apply: close the sink and retry later.
- *
- * Timeouts and Deadlines
- * This class offers two complementary controls to define a timeout policy.
- *
- * true
if this block contains lines.
- */
- public boolean hasLines() {
- return this.lines != null;
- }
-
- /**
- * Removes leading and trailing empty lines.
- */
- public void removeSurroundingEmptyLines() {
- if (this.lines != null) {
- this.removeTrailingEmptyLines();
- this.removeLeadingEmptyLines();
- }
- }
-
- /**
- * Sets hlDepth
and takes care of '#' chars.
- */
- public void transfromHeadline() {
- if (this.hlDepth > 0) {
- return;
- }
- int level = 0;
- final Line line = this.lines;
- if (line.isEmpty) {
- return;
- }
- int start = line.leading;
- while (start < line.value.length() && line.value.charAt(start) == '#') {
- level++;
- start++;
- }
- while (start < line.value.length() && line.value.charAt(start) == ' ') {
- start++;
- }
- if (start >= line.value.length()) {
- line.setEmpty();
- } else {
- int end = line.value.length() - line.trailing - 1;
- while (line.value.charAt(end) == '#') {
- end--;
- }
- while (line.value.charAt(end) == ' ') {
- end--;
- }
- line.value = line.value.substring(start, end + 1);
- line.leading = line.trailing = 0;
- }
- this.hlDepth = Math.min(level, 6);
- }
-
- /**
- * Used for nested lists. Removes list markers and up to 4 leading spaces.
- *
- * @param configuration txtmark configuration
- */
- public void removeListIndent(final Configuration configuration) {
- Line line = this.lines;
- while (line != null) {
- if (!line.isEmpty) {
- switch (line.getLineType(configuration)) {
- case ULIST:
- line.value = line.value.substring(line.leading + 2);
- break;
- case OLIST:
- line.value = line.value.substring(line.value.indexOf('.') + 2);
- break;
- default:
- line.value = line.value.substring(Math.min(line.leading, 4));
- break;
- }
- line.initLeading();
- }
- line = line.next;
- }
- }
-
- /**
- * Used for nested block quotes. Removes '>' char.
- */
- public void removeBlockQuotePrefix() {
- Line line = this.lines;
- while (line != null) {
- if (!line.isEmpty) {
- if (line.value.charAt(line.leading) == '>') {
- int rem = line.leading + 1;
- if (line.leading + 1 < line.value.length() && line.value.charAt(line.leading + 1) == ' ') {
- rem++;
- }
- line.value = line.value.substring(rem);
- line.initLeading();
- }
- }
- line = line.next;
- }
- }
-
- /**
- * Removes leading empty lines.
- *
- * @return true
if an empty line was removed.
- */
- public boolean removeLeadingEmptyLines() {
- boolean wasEmpty = false;
- Line line = this.lines;
- while (line != null && line.isEmpty) {
- this.removeLine(line);
- line = this.lines;
- wasEmpty = true;
- }
- return wasEmpty;
- }
-
- /**
- * Removes trailing empty lines.
- */
- public void removeTrailingEmptyLines() {
- Line line = this.lineTail;
- while (line != null && line.isEmpty) {
- this.removeLine(line);
- line = this.lineTail;
- }
- }
-
- /**
- * Splits this block's lines, creating a new child block having 'line' as
- * it's lineTail.
- *
- * @param line The line to split from.
- * @return The newly created Block.
- */
- public Block split(final Line line) {
- final Block block = new Block();
-
- block.lines = this.lines;
- block.lineTail = line;
- this.lines = line.next;
- line.next = null;
- if (this.lines == null) {
- this.lineTail = null;
- } else {
- this.lines.previous = null;
- }
-
- if (this.blocks == null) {
- this.blocks = this.blockTail = block;
- } else {
- this.blockTail.next = block;
- this.blockTail = block;
- }
-
- return block;
- }
-
- /**
- * Removes the given line from this block.
- *
- * @param line Line to remove.
- */
- public void removeLine(final Line line) {
- if (line.previous == null) {
- this.lines = line.next;
- } else {
- line.previous.next = line.next;
- }
- if (line.next == null) {
- this.lineTail = line.previous;
- } else {
- line.next.previous = line.previous;
- }
- line.previous = line.next = null;
- }
-
- /**
- * Appends the given line to this block.
- *
- * @param line Line to append.
- */
- public void appendLine(final Line line) {
- if (this.lineTail == null) {
- this.lines = this.lineTail = line;
- } else {
- this.lineTail.nextEmpty = line.isEmpty;
- line.prevEmpty = this.lineTail.isEmpty;
- line.previous = this.lineTail;
- this.lineTail.next = line;
- this.lineTail = line;
- }
- }
-
- /**
- * Changes all Blocks of type NONE
to PARAGRAPH
if
- * this Block is a List and any of the ListItems contains a paragraph.
- */
- public void expandListParagraphs() {
- if (this.type != BlockType.ORDERED_LIST && this.type != BlockType.UNORDERED_LIST) {
- return;
- }
- Block outer = this.blocks, inner;
- boolean hasParagraph = false;
- while (outer != null && !hasParagraph) {
- if (outer.type == BlockType.LIST_ITEM) {
- inner = outer.blocks;
- while (inner != null && !hasParagraph) {
- if (inner.type == BlockType.PARAGRAPH) {
- hasParagraph = true;
- }
- inner = inner.next;
- }
- }
- outer = outer.next;
- }
- if (hasParagraph) {
- outer = this.blocks;
- while (outer != null) {
- if (outer.type == BlockType.LIST_ITEM) {
- inner = outer.blocks;
- while (inner != null) {
- if (inner.type == BlockType.NONE) {
- inner.type = BlockType.PARAGRAPH;
- }
- inner = inner.next;
- }
- }
- outer = outer.next;
- }
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/BlockEmitter.java b/contentstack/src/main/java/com/contentstack/txtmark/BlockEmitter.java
deleted file mode 100755
index 37d2a029..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/BlockEmitter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke
- *
- *
- * @author René Jeschke <, rene_jeschke@yahoo.de>,
- * @since 0.7
- */
-public interface BlockEmitter {
- /**
- * This method is responsible for outputting a markdown block and for any
- * needed pre-processing like escaping HTML special characters.
- *
- * @param out The StringBuilder to append to
- * @param lines List of lines
- * @param meta Meta information as a single String (if any) or empty String
- */
- public void emitBlock(StringBuilder out, Listpublic void emitBlock(StringBuilder out, List<String> lines, String meta)
- * {
- * out.append("<pre><code>");
- * for(final String s : lines)
- * {
- * for(int i = 0; i < s.length(); i++)
- * {
- * final char c = s.charAt(i);
- * switch(c)
- * {
- * case '&':
- * out.append("&");
- * break;
- * case '<':
- * out.append("<");
- * break;
- * case '>':
- * out.append(">");
- * break;
- * default:
- * out.append(c);
- * break;
- * }
- * }
- * out.append('\n');
- * }
- * out.append("</code></pre>\n");
- * }
- *
- * process
- * methods
- *
- *
- */
- public final static Configuration DEFAULT = Configuration.builder().build();
-
- /**
- * safeMode = false
encoding = UTF-8
decorator = DefaultDecorator
codeBlockEmitter = null
- *
- */
- public final static Configuration DEFAULT_SAFE = Configuration.builder().enableSafeMode().build();
-
- /**
- * Constructor.
- */
- Configuration(final boolean safeMode, final String encoding, final Decorator decorator,
- final BlockEmitter codeBlockEmitter,
- final boolean forceExtendedProfile, final SpanEmitter specialLinkEmitter,
- final boolean allowSpacesInFencedDelimiters, final boolean panicMode) {
- this.safeMode = safeMode;
- this.encoding = encoding;
- this.decorator = decorator;
- this.codeBlockEmitter = codeBlockEmitter;
- this.forceExtendedProfile = forceExtendedProfile;
- this.specialLinkEmitter = specialLinkEmitter;
- this.allowSpacesInFencedDelimiters = allowSpacesInFencedDelimiters;
- this.panicMode = panicMode;
- }
-
- /**
- * Creates a new Builder instance.
- *
- * @return A new Builder instance.
- */
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * Configuration builder.
- *
- * @author René Jeschke <, rene_jeschke@yahoo.de>,
- * @since 0.7
- */
- public static class Builder {
- private boolean safeMode = false;
- private boolean panicMode = false;
- private boolean forceExtendedProfile = false;
- private boolean allowSpacesInFencedDelimiters = true;
- private String encoding = "UTF-8";
- private Decorator decorator = new DefaultDecorator();
- private BlockEmitter codeBlockEmitter = null;
- private SpanEmitter specialLinkEmitter = null;
-
- /**
- * Constructor.
- */
- Builder() {
- // empty
- }
-
- /**
- * Enables HTML safe mode.
- * safeMode = true
encoding = UTF-8
decorator = DefaultDecorator
codeBlockEmitter = null
false
- *
- * @return This builder
- * @since 0.7
- */
- public Builder enableSafeMode() {
- this.safeMode = true;
- return this;
- }
-
- /**
- * Forces extened profile to be enabled by default.
- *
- * @return This builder.
- * @since 0.7
- */
- public Builder forceExtentedProfile() {
- this.forceExtendedProfile = true;
- return this;
- }
-
- /**
- * Sets the HTML safe mode flag.
- * false
- *
- * @param flag true
to enable safe mode
- * @return This builder
- * @since 0.7
- */
- public Builder setSafeMode(final boolean flag) {
- this.safeMode = flag;
- return this;
- }
-
- /**
- * Sets the character encoding for txtmark.
- * "UTF-8"
- *
- * @param encoding The encoding
- * @return This builder
- * @since 0.7
- */
- public Builder setEncoding(final String encoding) {
- this.encoding = encoding;
- return this;
- }
-
- /**
- * Sets the decorator for txtmark.
- * DefaultDecorator()
- *
- * @param decorator The decorator
- * @return This builder
- * @see DefaultDecorator
- * @since 0.7
- */
- public Builder setDecorator(final Decorator decorator) {
- this.decorator = decorator;
- return this;
- }
-
- /**
- * Sets the code block emitter.
- * null
- *
- * @param emitter The BlockEmitter
- * @return This builder
- * @see BlockEmitter
- * @since 0.7
- */
- public Builder setCodeBlockEmitter(final BlockEmitter emitter) {
- this.codeBlockEmitter = emitter;
- return this;
- }
-
- /**
- * Sets the emitter for special link spans ([[ ... ]]).
- *
- * @param emitter The emitter.
- * @return This builder.
- * @since 0.7
- */
- public Builder setSpecialLinkEmitter(final SpanEmitter emitter) {
- this.specialLinkEmitter = emitter;
- return this;
- }
-
- /**
- * (Dis-)Allows spaces in fenced code block delimiter lines.
- *
- * @param allow whether to allow or not
- * @return This builder.
- * @since 0.12
- */
- public Builder setAllowSpacesInFencedCodeBlockDelimiters(final boolean allow) {
- this.allowSpacesInFencedDelimiters = allow;
- return this;
- }
-
- /**
- * This allows you to enable 'panicMode'. When 'panicMode' is enabled,
- * every {@code <} encountered will then be translated into {@code <}
- *
- * @param panic whether to enable or not
- * @return This builder.
- * @since 0.12
- */
- public Builder setEnablePanicMode(final boolean panic) {
- this.panicMode = panic;
- return this;
- }
-
- /**
- * This allows you to enable 'panicMode'. When 'panicMode' is enabled,
- * every {@code <} encountered will then be translated into {@code <}
- *
- * @return This builder.
- * @since 0.12
- */
- public Builder enablePanicMode() {
- this.panicMode = true;
- return this;
- }
-
- /**
- * Builds a configuration instance.
- *
- * @return a Configuration instance
- * @since 0.7
- */
- public Configuration build() {
- return new Configuration(this.safeMode, this.encoding, this.decorator, this.codeBlockEmitter,
- this.forceExtendedProfile, this.specialLinkEmitter, this.allowSpacesInFencedDelimiters,
- this.panicMode);
- }
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/Decorator.java b/contentstack/src/main/java/com/contentstack/txtmark/Decorator.java
deleted file mode 100755
index a571c13f..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/Decorator.java
+++ /dev/null
@@ -1,657 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openParagraph(final StringBuilder out);
-
- /**
- * Called when a paragraph is closed.
- *
- * out.append("<p>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeParagraph(final StringBuilder out);
-
- /**
- * Called when a blockquote is opened.
- * out.append("</p>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openBlockquote(final StringBuilder out);
-
- /**
- * Called when a blockquote is closed.
- *
- * out.append("<blockquote>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeBlockquote(final StringBuilder out);
-
- /**
- * Called when a code block is opened.
- *
- * out.append("</blockquote>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openCodeBlock(final StringBuilder out);
-
- /**
- * Called when a code block is closed.
- *
- * out.append("<pre><code>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeCodeBlock(final StringBuilder out);
-
- /**
- * Called when a code span is opened.
- *
- * out.append("</code></pre>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openCodeSpan(final StringBuilder out);
-
- /**
- * Called when a code span is closed.
- *
- * out.append("<code>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeCodeSpan(final StringBuilder out);
-
- /**
- * Called when a headline is opened.
- *
- * out.append("</code>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- * @param level The level to use.
- */
- public void openHeadline(final StringBuilder out, int level);
-
- /**
- * Called when a headline is closed.
- *
- * out.append("<h");
- * out.append(level);
- *
- *
- *
- * @param out The StringBuilder to write to.
- * @param level The level to use.
- */
- public void closeHeadline(final StringBuilder out, int level);
-
- /**
- * Called when a strong span is opened.
- *
- * out.append("</h");
- * out.append(level);
- * out.append(">\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openStrong(final StringBuilder out);
-
- /**
- * Called when a strong span is closed.
- *
- * out.append("<strong>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeStrong(final StringBuilder out);
-
- /**
- * Called when an emphasis span is opened.
- *
- * out.append("</strong>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openEmphasis(final StringBuilder out);
-
- /**
- * Called when an emphasis span is closed.
- *
- * out.append("<em>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeEmphasis(final StringBuilder out);
-
- /**
- * Called when a strikeout span is opened.
- *
- * out.append("</em>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openStrikeout(final StringBuilder out);
-
- /**
- * Called when a strikeout span is closed.
- *
- * out.append("<del>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeStrikeout(final StringBuilder out);
-
- /**
- * Called when a superscript span is opened.
- *
- * out.append("</del>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openSuper(final StringBuilder out);
-
- /**
- * Called when a superscript span is closed.
- *
- * out.append("<sup>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeSuper(final StringBuilder out);
-
- /**
- * Called when an ordered list is opened.
- *
- * out.append("</sup>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openOrderedList(final StringBuilder out);
-
- /**
- * Called when an ordered list is closed.
- *
- * out.append("<ol>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeOrderedList(final StringBuilder out);
-
- /**
- * Called when an unordered list is opened.
- *
- * out.append("</ol>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openUnorderedList(final StringBuilder out);
-
- /**
- * Called when an unordered list is closed.
- *
- * out.append("<ul>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeUnorderedList(final StringBuilder out);
-
- /**
- * Called when a list item is opened.
- *
- * out.append("</ul>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openListItem(final StringBuilder out);
-
- /**
- * Called when a list item is closed.
- *
- * out.append("<li");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeListItem(final StringBuilder out);
-
- /**
- * Called when a horizontal ruler is encountered.
- *
- * out.append("</li>\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void horizontalRuler(final StringBuilder out);
-
- /**
- * Called when a link is opened.
- *
- * out.append("<hr />\n");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openLink(final StringBuilder out);
-
- /**
- * Called when a link is closed
- *
- * out.append("<a");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeLink(final StringBuilder out);
-
- /**
- * Called when an image is opened.
- *
- * out.append("</a>");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openImage(final StringBuilder out);
-
- /**
- * Called when an image is closed.
- *
- * out.append("<img");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeImage(final StringBuilder out);
-
- /**
- * Called when a table is opened.
- *
- * out.append(" />");
- *
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTable(final StringBuilder out);
-
- /**
- * Called when a table body is opened.
- *
- * out.append("
- * ");
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openTable(final StringBuilder out);
-
- /**
- * Called when a table is closed.
- *
- *
");
- *
out.append("
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTableBody(final StringBuilder out);
-
- /**
- * Called when a table head is opened.
- *
- * out.append("");
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openTableBody(final StringBuilder out);
-
- /**
- * Called when a table body is closed.
- *
- *
- *
- *
");out.append("
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTableHead(final StringBuilder out);
-
- /**
- * Called when a table row is opened.
- *
- * out.append("");
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openTableHead(final StringBuilder out);
-
- /**
- * Called when a table head is closed.
- *
- *
- *
- *
");out.append("
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTableRow(final StringBuilder out);
-
- /**
- * Called when a table data is opened.
- *
- * out.append("
- * ");
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void openTableRow(final StringBuilder out);
-
- /**
- * Called when a table row is closed.
- *
- * ");
- *
out.append("
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTableData(final StringBuilder out);
-
- /**
- * Called when a table header is opened.
- *
- * out.append("
- * ");
- *
- *
- * @param out The StringBuilder to write to.
- * @param align one of null | left | center | right.
- * If null no align is set
- */
- public void openTableData(final StringBuilder out, final String align);
-
- /**
- * Called when a table data is closed.
- *
- * ");
- *
out.append("
- *
- *
- * @param out The StringBuilder to write to.
- */
- public void closeTableHeader(final StringBuilder out);
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/DefaultDecorator.java b/contentstack/src/main/java/com/contentstack/txtmark/DefaultDecorator.java
deleted file mode 100755
index 95811d1d..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/DefaultDecorator.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke out.append("
- * ");
- *
- *
- * @param out The StringBuilder to write to.
- * @param align one of null | left | center | right.
- * If null no align is set
- */
- public void openTableHeader(final StringBuilder out, final String align);
-
- /**
- * Called when a table header is closed.
- *
- * ");
- *
out.append("
- *
- *
- * @author René Jeschke <rene_jeschke@yahoo.de>
- */
-public class DefaultDecorator implements Decorator {
- /**
- * Constructor.
- */
- public DefaultDecorator() {
- // empty
- }
-
- /**
- * @see Decorator#openParagraph(StringBuilder)
- */
- @Override
- public void openParagraph(final StringBuilder out) {
- out.append("public class MyDecorator extends DefaultDecorator
- * {
- * @Override
- * public void openParagraph(StringBuilder out)
- * {
- * out.append("<p class=\"myclass\">");
- * }
- * }
- *
- * ");
- }
-
- /**
- * @see Decorator#closeBlockquote(StringBuilder)
- */
- @Override
- public void closeBlockquote(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openCodeBlock(StringBuilder)
- */
- @Override
- public void openCodeBlock(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openCodeSpan(StringBuilder)
- */
- @Override
- public void openCodeSpan(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#closeCodeBlock(StringBuilder)
- */
- @Override
- public void closeCodeBlock(final StringBuilder out) {
- out.append("
");
- }
-
- /**
- * @see Decorator#closeCodeSpan(StringBuilder)
- */
- @Override
- public void closeCodeSpan(final StringBuilder out) {
- out.append("
");
- }
-
- /**
- * @see Decorator#openHeadline(StringBuilder,
- * int)
- */
- @Override
- public void openHeadline(final StringBuilder out, final int level) {
- out.append("");
- }
-
- /**
- * @see Decorator#closeStrikeout(StringBuilder)
- */
- @Override
- public void closeStrikeout(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#openSuper(StringBuilder)
- */
- @Override
- public void openSuper(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#closeSuper(StringBuilder)
- */
- @Override
- public void closeSuper(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#openOrderedList(StringBuilder)
- */
- @Override
- public void openOrderedList(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeOrderedList(StringBuilder)
- */
- @Override
- public void closeOrderedList(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openUnorderedList(StringBuilder)
- */
- @Override
- public void openUnorderedList(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeUnorderedList(StringBuilder)
- */
- @Override
- public void closeUnorderedList(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openListItem(StringBuilder)
- */
- @Override
- public void openListItem(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openLink(StringBuilder)
- */
- @Override
- public void openLink(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#openImage(StringBuilder)
- */
- @Override
- public void openImage(final StringBuilder out) {
- out.append("");
- }
-
- /**
- * @see Decorator#openTable(java.lang.StringBuilder)
- */
- @Override
- public void openTable(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeTable(java.lang.StringBuilder)
- */
- @Override
- public void closeTable(final StringBuilder out) {
- out.append("
\n");
- }
-
- /**
- * @see Decorator#openTableHead(java.lang.StringBuilder)
- */
- @Override
- public void openTableHead(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeTableHead(java.lang.StringBuilder)
- */
- @Override
- public void closeTableHead(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#openTableBody(java.lang.StringBuilder)
- */
- @Override
- public void openTableBody(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeTableBody(java.lang.StringBuilder)
- */
- @Override
- public void closeTableBody(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#openTableRow(java.lang.StringBuilder)
- */
- @Override
- public void openTableRow(final StringBuilder out) {
- out.append("\n");
- }
-
- /**
- * @see Decorator#closeTableRow(java.lang.StringBuilder)
- */
- @Override
- public void closeTableRow(final StringBuilder out) {
- out.append(" \n");
- }
-
- /**
- * @see Decorator#openTableData(java.lang.StringBuilder, java.lang.String)
- */
- @Override
- public void openTableData(final StringBuilder out, final String align) {
- if (align == null) {
- out.append("");
- } else {
- out.append(" ");
- }
- }
-
- /**
- * @see Decorator#closeTableData(java.lang.StringBuilder)
- */
- @Override
- public void closeTableData(final StringBuilder out) {
- out.append(" ");
- }
-
- /**
- * @see Decorator#openTableHeader(java.lang.StringBuilder, java.lang.String)
- */
- @Override
- public void openTableHeader(final StringBuilder out, final String align) {
- if (align == null) {
- out.append("");
- } else {
- out.append(" ");
- }
- }
-
- /**
- * @see Decorator#closeTableHeader(java.lang.StringBuilder)
- */
- @Override
- public void closeTableHeader(final StringBuilder out) {
- out.append(" ");
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/Emitter.java b/contentstack/src/main/java/com/contentstack/txtmark/Emitter.java
deleted file mode 100755
index abc15ee7..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/Emitter.java
+++ /dev/null
@@ -1,1010 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke
");
- }
- }
- if (line.next != null) {
- in.append('\n');
- }
- line = line.next;
- }
-
- this.recursiveEmitLine(out, in.toString(), 0, MarkToken.NONE);
- }
-
- /**
- * Writes a set of raw lines into the StringBuilder.
- *
- * @param out The StringBuilder to write to.
- * @param lines The lines to write.
- */
- private void emitRawLines(final StringBuilder out, final Line lines) {
- Line line = lines;
- if (this.config.safeMode) {
- final StringBuilder temp = new StringBuilder();
- while (line != null) {
- if (!line.isEmpty) {
- temp.append(line.value);
- }
- temp.append('\n');
- line = line.next;
- }
- final String in = temp.toString();
- for (int pos = 0; pos < in.length(); pos++) {
- if (in.charAt(pos) == '<') {
- temp.setLength(0);
- final int t = Utils.readXML(temp, in, pos, this.config.safeMode);
- if (t != -1) {
- out.append(temp);
- pos = t;
- } else {
- out.append(in.charAt(pos));
- }
- } else {
- out.append(in.charAt(pos));
- }
- }
- } else {
- while (line != null) {
- if (!line.isEmpty) {
- out.append(line.value);
- }
- out.append('\n');
- line = line.next;
- }
- }
- }
-
- /**
- * Writes a code block into the StringBuilder.
- *
- * @param out The StringBuilder to write to.
- * @param lines The lines to write.
- * @param meta Meta information.
- */
- private void emitCodeLines(final StringBuilder out, final Line lines, final String meta, final boolean removeIndent) {
- Line line = lines;
- if (this.config.codeBlockEmitter != null) {
- final ArrayListtrue
if the given String is a link prefix.
- */
- public final static boolean isLinkPrefix(final String value) {
- return LINK_PREFIX.contains(value);
- }
-
- /**
- * @param value String to check.
- * @return Returns true
if the given String is an entity.
- */
- public final static boolean isEntity(final String value) {
- return decodeMap.containsKey(value);
- }
-
- /**
- * @param value String to check.
- * @return Returns true
if the given String is a HTML tag.
- */
- public final static boolean isHtmlElement(final String value) {
- return HTML_ELEMENTS.contains(value);
- }
-
- /**
- * @param value String to check.
- * @return Returns true
if the given String is a HTML block
- * level tag.
- */
- public final static boolean isHtmlBlockElement(final String value) {
- return HTML_BLOCK_ELEMENTS.contains(value);
- }
-
- /**
- * @param value String to check.
- * @return Returns true
if the given String is an unsafe HTML
- * tag.
- */
- public final static boolean isUnsafeHtmlElement(final String value) {
- return HTML_UNSAFE.contains(value);
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/HTMLElement.java b/contentstack/src/main/java/com/contentstack/txtmark/HTMLElement.java
deleted file mode 100755
index 157ba9de..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/HTMLElement.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke false
if end of line is reached
- */
- public boolean skipSpaces() {
- while (this.pos < this.value.length() && this.value.charAt(this.pos) == ' ') {
- this.pos++;
- }
- return this.pos < this.value.length();
- }
-
- /**
- * Reads chars from this line until any 'end' char is reached.
- *
- * @param end Delimiting character(s)
- * @return The read String or null
if no 'end' char was
- * reached.
- */
- public String readUntil(final char... end) {
- final StringBuilder sb = new StringBuilder();
- int pos = this.pos;
- while (pos < this.value.length()) {
- final char ch = this.value.charAt(pos);
- if (ch == '\\' && pos + 1 < this.value.length()) {
- final char c;
- switch (c = this.value.charAt(pos + 1)) {
- case '\\':
- case '[':
- case ']':
- case '(':
- case ')':
- case '{':
- case '}':
- case '#':
- case '"':
- case '\'':
- case '.':
- case '>':
- case '*':
- case '+':
- case '-':
- case '_':
- case '!':
- case '`':
- case '~':
- sb.append(c);
- pos++;
- break;
- default:
- sb.append(ch);
- break;
- }
- } else {
- boolean endReached = false;
- for (int n = 0; n < end.length; n++) {
- if (ch == end[n]) {
- endReached = true;
- break;
- }
- }
- if (endReached) {
- break;
- }
- sb.append(ch);
- }
- pos++;
- }
-
- final char ch = pos < this.value.length() ? this.value.charAt(pos) : '\n';
- for (int n = 0; n < end.length; n++) {
- if (ch == end[n]) {
- this.pos = pos;
- return sb.toString();
- }
- }
- return null;
- }
-
- /**
- * Marks this line empty. Also sets previous/next line's empty attributes.
- */
- public void setEmpty() {
- this.value = "";
- this.leading = this.trailing = 0;
- this.isEmpty = true;
- if (this.previous != null) {
- this.previous.nextEmpty = true;
- }
- if (this.next != null) {
- this.next.prevEmpty = true;
- }
- }
-
- /**
- * Counts the amount of 'ch' in this line.
- *
- * @param ch The char to count.
- * @return A value > 0 if this line only consists of 'ch' end spaces.
- */
- private int countChars(final char ch) {
- int count = 0;
- for (int i = 0; i < this.value.length(); i++) {
- final char c = this.value.charAt(i);
- if (c == ' ') {
- continue;
- }
- if (c == ch) {
- count++;
- continue;
- }
- count = 0;
- break;
- }
- return count;
- }
-
- /**
- * Counts the amount of 'ch' at the start of this line optionally ignoring
- * spaces.
- *
- * @param ch The char to count.
- * @param allowSpaces Whether to allow spaces or not
- * @return Number of characters found.
- * @since 0.12
- */
- private int countCharsStart(final char ch, final boolean allowSpaces) {
- int count = 0;
- for (int i = 0; i < this.value.length(); i++) {
- final char c = this.value.charAt(i);
- if (c == ' ' && allowSpaces) {
- continue;
- }
- if (c == ch) {
- count++;
- } else {
- break;
- }
- }
- return count;
- }
-
- /**
- * Gets this line's type.
- *
- * @param configuration txtmark configuration
- * @return The LineType.
- */
- public LineType getLineType(final Configuration configuration) {
- if (this.isEmpty) {
- return LineType.EMPTY;
- }
-
- if (this.leading > 3) {
- return LineType.CODE;
- }
-
- if (this.value.charAt(this.leading) == '#') {
- return LineType.HEADLINE;
- }
-
- if (this.value.charAt(this.leading) == '>') {
- return LineType.BQUOTE;
- }
-
- if (configuration.forceExtendedProfile) {
- if (this.value.length() - this.leading - this.trailing > 2) {
- if (this.value.charAt(this.leading) == '`'
- && this.countCharsStart('`', configuration.allowSpacesInFencedDelimiters) >= 3) {
- return LineType.FENCED_CODE;
- }
- if (this.value.charAt(this.leading) == '~'
- && this.countCharsStart('~', configuration.allowSpacesInFencedDelimiters) >= 3) {
- return LineType.FENCED_CODE;
- }
- }
- }
-
- if (this.value.length() - this.leading - this.trailing > 2
- && (this.value.charAt(this.leading) == '*' || this.value.charAt(this.leading) == '-' || this.value
- .charAt(this.leading) == '_')) {
- if (this.countChars(this.value.charAt(this.leading)) >= 3) {
- return LineType.HR;
- }
- }
-
- if (this.value.length() - this.leading >= 2 && this.value.charAt(this.leading + 1) == ' ') {
- switch (this.value.charAt(this.leading)) {
- case '*':
- case '-':
- case '+':
- return LineType.ULIST;
- }
- }
-
- if (this.value.length() - this.leading >= 3 && Character.isDigit(this.value.charAt(this.leading))) {
- int i = this.leading + 1;
- while (i < this.value.length() && Character.isDigit(this.value.charAt(i))) {
- i++;
- }
- if (i + 1 < this.value.length() && this.value.charAt(i) == '.' && this.value.charAt(i + 1) == ' ') {
- return LineType.OLIST;
- }
- }
-
- if (this.value.charAt(this.leading) == '<') {
- if (this.checkHTML()) {
- return LineType.XML;
- }
- }
-
- if (this.next != null && !this.next.isEmpty) {
- if ((this.next.value.charAt(0) == '-') && (this.next.countChars('-') > 0)) {
- return LineType.HEADLINE2;
- }
- if ((this.next.value.charAt(0) == '=') && (this.next.countChars('=') > 0)) {
- return LineType.HEADLINE1;
- }
- if (configuration.forceExtendedProfile && (this.previous == null || this.previous.isEmpty)) {
- TableDef table = TableDef.parse(this.value, this.next.value);
- if (table != null) {
- this.data = table; // attach the table definition to be used later
- return LineType.TABLE;
- }
- }
- }
-
- return LineType.OTHER;
- }
-
- /**
- * Reads an XML comment. Sets xmlEndLine
.
- *
- * @param firstLine The Line to start reading from.
- * @param start The starting position.
- * @return The new position or -1 if it is no valid comment.
- */
- private int readXMLComment(final Line firstLine, final int start) {
- Line line = firstLine;
- if (start + 3 < line.value.length()) {
- if (line.value.charAt(2) == '-' && line.value.charAt(3) == '-') {
- int pos = start + 4;
- while (line != null) {
- while (pos < line.value.length() && line.value.charAt(pos) != '-') {
- pos++;
- }
- if (pos == line.value.length()) {
- line = line.next;
- pos = 0;
- } else {
- if (pos + 2 < line.value.length()) {
- if (line.value.charAt(pos + 1) == '-' && line.value.charAt(pos + 2) == '>') {
- this.xmlEndLine = line;
- return pos + 3;
- }
- }
- pos++;
- }
- }
- }
- }
- return -1;
- }
-
- /**
- * Checks if this line contains an ID at it's end and removes it from the
- * line.
- *
- * @return The ID or null
if no valid ID exists.
- */
- public String stripID() {
- if (this.isEmpty || this.value.charAt(this.value.length() - this.trailing - 1) != '}') {
- return null;
- }
- int p = this.leading;
- boolean found = false;
- while (p < this.value.length() && !found) {
- switch (this.value.charAt(p)) {
- case '\\':
- if (p + 1 < this.value.length()) {
- switch (this.value.charAt(p + 1)) {
- case '{':
- p++;
- break;
- }
- }
- p++;
- break;
- case '{':
- found = true;
- break;
- default:
- p++;
- break;
- }
- }
-
- if (found) {
- if (p + 1 < this.value.length() && this.value.charAt(p + 1) == '#') {
- final int start = p + 2;
- p = start;
- found = false;
- while (p < this.value.length() && !found) {
- switch (this.value.charAt(p)) {
- case '\\':
- if (p + 1 < this.value.length()) {
- switch (this.value.charAt(p + 1)) {
- case '}':
- p++;
- break;
- }
- }
- p++;
- break;
- case '}':
- found = true;
- break;
- default:
- p++;
- break;
- }
- }
- if (found) {
- final String id = this.value.substring(start, p).trim();
- if (this.leading != 0) {
- this.value = this.value.substring(0, this.leading)
- + this.value.substring(this.leading, start - 2).trim();
- } else {
- this.value = this.value.substring(this.leading, start - 2).trim();
- }
- this.trailing = 0;
- return id.length() > 0 ? id : null;
- }
- }
- }
- return null;
- }
-
- /**
- * Checks for a valid HTML block. Sets xmlEndLine
.
- *
- * @return true
if it is a valid block.
- */
- private boolean checkHTML() {
- final LinkedListnull
).
- */
- public LinkRef(final String link, final String title, final boolean isAbbrev) {
- this.link = link;
- this.title = title;
- this.isAbbrev = isAbbrev;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return this.link + " \"" + this.title + "\"";
- }
-}
diff --git a/contentstack/src/main/java/com/contentstack/txtmark/MarkToken.java b/contentstack/src/main/java/com/contentstack/txtmark/MarkToken.java
deleted file mode 100755
index d974aa0b..00000000
--- a/contentstack/src/main/java/com/contentstack/txtmark/MarkToken.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2011-2015 René Jeschke
- *
- *
- * @author René Jeschke <, rene_jeschke@yahoo.de>,
- */
-public class Processor {
- /**
- * The reader.
- */
- private final Reader reader;
- /**
- * The emitter.
- */
- private final Emitter emitter;
- /**
- * The Configuration.
- */
- final Configuration config;
- /**
- * Extension flag.
- */
- private boolean useExtensions = false;
-
- /**
- * Constructor.
- *
- * @param reader The input reader.
- */
- private Processor(final Reader reader, final Configuration config) {
- this.reader = reader;
- this.config = config;
- this.useExtensions = config.forceExtendedProfile;
- this.emitter = new Emitter(this.config);
- }
-
- /**
- * Transforms an input stream into HTML using the given Configuration.
- *
- * @param reader The Reader to process.
- * @param configuration The Configuration.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration
- * @since 0.7
- */
- public final static String process(final Reader reader, final Configuration configuration) throws IOException {
- final Processor p = new Processor(!(reader instanceof BufferedReader) ? new BufferedReader(reader) : reader,
- configuration);
- return p.process();
- }
-
- /**
- * Transforms an input String into HTML using the given Configuration.
- *
- * @param input The String to process.
- * @param configuration The Configuration.
- * @return The processed String.
- * @see Configuration
- * @since 0.7
- */
- public final static String process(final String input, final Configuration configuration) {
- try {
- return process(new StringReader(input), configuration);
- } catch (final IOException e) {
- // This _can never_ happen
- return null;
- }
- }
-
- /**
- * Transforms an input file into HTML using the given Configuration.
- *
- * @param file The File to process.
- * @param configuration the Configuration
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration
- * @since 0.7
- */
- public final static String process(final File file, final Configuration configuration) throws IOException {
- final FileInputStream input = new FileInputStream(file);
- final String ret = process(input, configuration);
- input.close();
- return ret;
- }
-
- /**
- * Transforms an input stream into HTML using the given Configuration.
- *
- * @param input The InputStream to process.
- * @param configuration The Configuration.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration
- * @since 0.7
- */
- public final static String process(final InputStream input, final Configuration configuration) throws IOException {
- final Processor p = new Processor(new BufferedReader(new InputStreamReader(input, configuration.encoding)),
- configuration);
- return p.process();
- }
-
- /**
- * Transforms an input String into HTML using the default Configuration.
- *
- * @param input The String to process.
- * @return The processed String.
- * @see Configuration#DEFAULT
- */
- public final static String process(final String input) {
- return process(input, Configuration.DEFAULT);
- }
-
- /**
- * Transforms an input String into HTML.
- *
- * @param input The String to process.
- * @param safeMode Set to String result = Processor.process("This is ***TXTMARK***");
- *
- * true
to escape unsafe HTML tags.
- * @return The processed String.
- * @see Configuration#DEFAULT
- */
- public final static String process(final String input, final boolean safeMode) {
- return process(input, Configuration.builder().setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input String into HTML.
- *
- * @param input The String to process.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @see Configuration#DEFAULT
- */
- public final static String process(final String input, final Decorator decorator) {
- return process(input, Configuration.builder().setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input String into HTML.
- *
- * @param input The String to process.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @see Configuration#DEFAULT
- */
- public final static String process(final String input, final Decorator decorator, final boolean safeMode) {
- return process(input, Configuration.builder().setDecorator(decorator).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input file into HTML using the default Configuration.
- *
- * @param file The File to process.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file) throws IOException {
- return process(file, Configuration.DEFAULT);
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final boolean safeMode) throws IOException {
- return process(file, Configuration.builder().setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final Decorator decorator) throws IOException {
- return process(file, Configuration.builder().setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final Decorator decorator, final boolean safeMode)
- throws IOException {
- return process(file, Configuration.builder().setDecorator(decorator).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param encoding The encoding to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final String encoding) throws IOException {
- return process(file, Configuration.builder().setEncoding(encoding).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param encoding The encoding to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final String encoding, final boolean safeMode)
- throws IOException {
- return process(file, Configuration.builder().setEncoding(encoding).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param encoding The encoding to use.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final String encoding, final Decorator decorator)
- throws IOException {
- return process(file, Configuration.builder().setEncoding(encoding).setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input file into HTML.
- *
- * @param file The File to process.
- * @param encoding The encoding to use.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final File file, final String encoding, final Decorator decorator,
- final boolean safeMode) throws IOException {
- return process(file, Configuration.builder().setEncoding(encoding).setSafeMode(safeMode)
- .setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input) throws IOException {
- return process(input, Configuration.DEFAULT);
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final boolean safeMode) throws IOException {
- return process(input, Configuration.builder().setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final Decorator decorator) throws IOException {
- return process(input, Configuration.builder().setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final Decorator decorator, final boolean safeMode)
- throws IOException {
- return process(input, Configuration.builder().setDecorator(decorator).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param encoding The encoding to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final String encoding) throws IOException {
- return process(input, Configuration.builder().setEncoding(encoding).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param encoding The encoding to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final String encoding, final boolean safeMode)
- throws IOException {
- return process(input, Configuration.builder().setEncoding(encoding).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param encoding The encoding to use.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final String encoding, final Decorator decorator)
- throws IOException {
- return process(input, Configuration.builder().setEncoding(encoding).setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param input The InputStream to process.
- * @param encoding The encoding to use.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final InputStream input, final String encoding, final Decorator decorator,
- final boolean safeMode) throws IOException {
- return process(input,
- Configuration.builder().setEncoding(encoding).setDecorator(decorator).setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input stream into HTML using the default Configuration.
- *
- * @param reader The Reader to process.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final Reader reader) throws IOException {
- return process(reader, Configuration.DEFAULT);
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param reader The Reader to process.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final Reader reader, final boolean safeMode) throws IOException {
- return process(reader, Configuration.builder().setSafeMode(safeMode).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param reader The Reader to process.
- * @param decorator The decorator to use.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final Reader reader, final Decorator decorator) throws IOException {
- return process(reader, Configuration.builder().setDecorator(decorator).build());
- }
-
- /**
- * Transforms an input stream into HTML.
- *
- * @param reader The Reader to process.
- * @param decorator The decorator to use.
- * @param safeMode Set to true
to escape unsafe HTML tags.
- * @return The processed String.
- * @throws IOException if an IO error occurs
- * @see Configuration#DEFAULT
- */
- public final static String process(final Reader reader, final Decorator decorator, final boolean safeMode)
- throws IOException {
- return process(reader, Configuration.builder().setDecorator(decorator).setSafeMode(safeMode).build());
- }
-
- /**
- * Reads all lines from our reader.
- *
- *
- *
- * java -cp txtmark.jar txtmark.Run filename [header_footer_file]
- *
- * header_footer_file
is an optional UTF-8 encoded file
- * containing a header and a footer to output around the generated HTML code.
- *
- *
- *
- * @author René Jeschke <rene_jeschke@yahoo.de>
- */
-public class Run {
- /**
- * Static main.
- *
- * @param args Program arguments.
- * @throws IOException If an IO error occurred.
- */
- public static void main(final String[] args) throws IOException {
- // This is just a _hack_ ...
- BufferedReader reader = null;
- if (args.length == 0) {
- System.err.println("No input file specified.");
- System.exit(-1);
- }
- if (args.length > 1) {
- reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[1]), "UTF-8"));
- String line = reader.readLine();
- while (line != null && !line.startsWith("<?xml version="1.0" encoding="UTF-8"?>
- * <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- * <html xmlns="http://www.w3.org/1999/xhtml">
- * <head>
- * <title>markdown</title>
- * <link type="text/css" href="style.css" rel="stylesheet"/>
- * <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
- * </head>
- * <body>
- * <!-- the following line separates header from footer -->
- * <!-- ### -->
- * </body>
- * </html>
- *
- *