-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed options from 'Convert' functional interface. Removed options …
…from being able to be passed in on the convert() API. The options are used from the Convert instance, which was constructed with ConvertOptions.
- Loading branch information
Showing
39 changed files
with
1,734 additions
and
1,815 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 32 additions & 25 deletions
57
src/main/java/com/cedarsoftware/util/convert/ByteArrayConversions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,53 @@ | ||
package com.cedarsoftware.util.convert; | ||
|
||
import com.cedarsoftware.util.StringUtilities; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.CharBuffer; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public final class ByteArrayConversions { | ||
import com.cedarsoftware.util.StringUtilities; | ||
|
||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* 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 | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* 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. | ||
*/ | ||
final class ByteArrayConversions { | ||
|
||
private ByteArrayConversions() {} | ||
|
||
static String toString(Object from, ConverterOptions options) { | ||
static String toString(Object from, Converter converter) { | ||
byte[] bytes = (byte[])from; | ||
return (bytes == null) ? StringUtilities.EMPTY : new String(bytes, options.getCharset()); | ||
return (bytes == null) ? StringUtilities.EMPTY : new String(bytes, converter.getOptions().getCharset()); | ||
} | ||
|
||
static ByteBuffer toByteBuffer(Object from) { | ||
return ByteBuffer.wrap((byte[])from); | ||
static ByteBuffer toByteBuffer(Object from, Converter converter) { | ||
return ByteBuffer.wrap((byte[]) from); | ||
} | ||
|
||
static String toString(Object from, Converter converter, ConverterOptions options) { | ||
return toString(from, options); | ||
static CharBuffer toCharBuffer(Object from, Converter converter) { | ||
return CharBuffer.wrap(toString(from, converter)); | ||
} | ||
|
||
static ByteBuffer toByteBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return toByteBuffer(from); | ||
static char[] toCharArray(Object from, Converter converter) { | ||
return toString(from, converter).toCharArray(); | ||
} | ||
|
||
static CharBuffer toCharBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return CharBuffer.wrap(toString(from, options)); | ||
static StringBuffer toStringBuffer(Object from, Converter converter) { | ||
return new StringBuffer(toString(from, converter)); | ||
} | ||
|
||
static char[] toCharArray(Object from, Converter converter, ConverterOptions options) { | ||
return toString(from, options).toCharArray(); | ||
static StringBuilder toStringBuilder(Object from, Converter converter) { | ||
return new StringBuilder(toString(from, converter)); | ||
} | ||
|
||
static StringBuffer toStringBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return new StringBuffer(toString(from, options)); | ||
} | ||
|
||
static StringBuilder toStringBuilder(Object from, Converter converter, ConverterOptions options) { | ||
return new StringBuilder(toString(from, options)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,42 @@ | |
|
||
import static com.cedarsoftware.util.ArrayUtilities.EMPTY_BYTE_ARRAY; | ||
|
||
public final class ByteBufferConversions { | ||
/** | ||
* @author Kenny Partlow ([email protected]) | ||
* <br> | ||
* Copyright (c) Cedar Software LLC | ||
* <br><br> | ||
* 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 | ||
* <br><br> | ||
* <a href="http://www.apache.org/licenses/LICENSE-2.0">License</a> | ||
* <br><br> | ||
* 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. | ||
*/ | ||
final class ByteBufferConversions { | ||
|
||
private ByteBufferConversions() {} | ||
|
||
static CharBuffer toCharBuffer(Object from, Converter converter) { | ||
ByteBuffer buffer = toByteBuffer(from, converter); | ||
return converter.getOptions().getCharset().decode(buffer); | ||
} | ||
|
||
static ByteBuffer asReadOnlyBuffer(Object from) { | ||
static ByteBuffer toByteBuffer(Object from, Converter converter) { | ||
// Create a readonly buffer so we aren't changing | ||
// the original buffers mark and position when | ||
// working with this buffer. This could be inefficient | ||
// if constantly fed with writeable buffers so should be documented | ||
return ((ByteBuffer)from).asReadOnlyBuffer(); | ||
return ((ByteBuffer) from).asReadOnlyBuffer(); | ||
} | ||
|
||
static byte[] toByteArray(Object from) { | ||
ByteBuffer buffer = asReadOnlyBuffer(from); | ||
static byte[] toByteArray(Object from, Converter converter) { | ||
ByteBuffer buffer = toByteBuffer(from, converter); | ||
|
||
if (buffer == null || !buffer.hasRemaining()) { | ||
return EMPTY_BYTE_ARRAY; | ||
|
@@ -29,37 +51,19 @@ static byte[] toByteArray(Object from) { | |
return bytes; | ||
} | ||
|
||
static CharBuffer toCharBuffer(Object from, ConverterOptions options) { | ||
ByteBuffer buffer = asReadOnlyBuffer(from); | ||
return options.getCharset().decode(buffer); | ||
} | ||
|
||
static CharBuffer toCharBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return toCharBuffer(from, options); | ||
} | ||
|
||
static ByteBuffer toByteBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return asReadOnlyBuffer(from); | ||
static String toString(Object from, Converter converter) { | ||
return toCharBuffer(from, converter).toString(); | ||
} | ||
|
||
static byte[] toByteArray(Object from, Converter converter, ConverterOptions options) { | ||
return toByteArray(from); | ||
static char[] toCharArray(Object from, Converter converter) { | ||
return CharBufferConversions.toCharArray(toCharBuffer(from, converter), converter); | ||
} | ||
|
||
static String toString(Object from, Converter converter, ConverterOptions options) { | ||
return toCharBuffer(from, options).toString(); | ||
static StringBuffer toStringBuffer(Object from, Converter converter) { | ||
return new StringBuffer(toCharBuffer(from, converter)); | ||
} | ||
|
||
static char[] toCharArray(Object from, Converter converter, ConverterOptions options) { | ||
return CharBufferConversions.toCharArray(toCharBuffer(from, options)); | ||
static StringBuilder toStringBuilder(Object from, Converter converter) { | ||
return new StringBuilder(toCharBuffer(from, converter)); | ||
} | ||
|
||
static StringBuffer toStringBuffer(Object from, Converter converter, ConverterOptions options) { | ||
return new StringBuffer(toCharBuffer(from, options)); | ||
} | ||
|
||
static StringBuilder toStringBuilder(Object from, Converter converter, ConverterOptions options) { | ||
return new StringBuilder(toCharBuffer(from, options)); | ||
} | ||
|
||
} |
Oops, something went wrong.