You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2015/12/14 03:43:04 UTC
[1/2] zest-java git commit: ZEST-123 : Removed the Base64Encoder
class and use the one in the JDK instead.
Repository: zest-java
Updated Branches:
refs/heads/develop 22b4514e6 -> 4dabe5781
ZEST-123 : Removed the Base64Encoder class and use the one in the JDK instead.
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/c5ca22d3
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/c5ca22d3
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/c5ca22d3
Branch: refs/heads/develop
Commit: c5ca22d30ee6b0aa23a13529307b17608ee55555
Parents: 22b4514
Author: Niclas Hedhman <ni...@hedhman.org>
Authored: Mon Dec 14 10:36:40 2015 +0800
Committer: Niclas Hedhman <ni...@hedhman.org>
Committed: Mon Dec 14 10:42:57 2015 +0800
----------------------------------------------------------------------
.../org/apache/zest/api/util/Base64Encoder.java | 224 -------------------
.../spi/value/ValueDeserializerAdapter.java | 4 +-
.../zest/spi/value/ValueSerializerAdapter.java | 4 +-
.../zest/sample/forum/data/entity/User.java | 5 +-
4 files changed, 6 insertions(+), 231 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zest-java/blob/c5ca22d3/core/api/src/main/java/org/apache/zest/api/util/Base64Encoder.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/util/Base64Encoder.java b/core/api/src/main/java/org/apache/zest/api/util/Base64Encoder.java
deleted file mode 100644
index 2779d6e..0000000
--- a/core/api/src/main/java/org/apache/zest/api/util/Base64Encoder.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright 2009 Alin Dreghiciu.
- *
- * 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 org.apache.zest.api.util;
-
-/**
- * Base64Encoder.
- */
-public final class Base64Encoder
-{
-
- /**
- * Utility class. ment to be used via static methods.
- */
- private Base64Encoder()
- {
- // utility class
- }
-
- /**
- * Encodes a String into a base 64 String. The resulting encoding is chunked at 76 bytes.
- *
- * @param s String to encode.
- *
- * @return encoded string.
- */
- public static String encode( String s, boolean includePadding )
- {
- byte[] sBytes = s.getBytes();
- sBytes = encode( sBytes, includePadding );
- s = new String( sBytes );
- return s;
- }
-
- /**
- * Decodes a base 64 String into a String.
- *
- * @param s String to decode.
- *
- * @return encoded string.
- *
- * @throws java.lang.IllegalArgumentException
- * _ If the given byte array was not valid base64 encoding.
- */
- public static String decode( String s )
- throws IllegalArgumentException
- {
- s = s.replaceAll( "\n", "" );
- s = s.replaceAll( "\r", "" );
- byte[] sBytes = s.getBytes();
- sBytes = decode( sBytes );
- s = new String( sBytes );
- return s;
- }
-
- private static final byte[] ALPHASET =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".getBytes();
-
- private static final int I6O2 = 255 - 3;
- private static final int O6I2 = 3;
- private static final int I4O4 = 255 - 15;
- private static final int O4I4 = 15;
- private static final int I2O6 = 255 - 63;
- private static final int O2I6 = 63;
-
- /**
- * Encodes a byte array into a base 64 byte array.
- *
- * @param dData byte array to encode.
- *
- * @return encoded byte array.
- */
- public static byte[] encode( byte[] dData, boolean includePadding )
- {
- if( dData == null )
- {
- throw new IllegalArgumentException( "Cannot encode null" );
- }
- byte[] eData = new byte[ ( ( dData.length + 2 ) / 3 ) * 4 ];
-
- int eIndex = 0;
- for( int i = 0; i < dData.length; i += 3 )
- {
- int d1;
- int d2 = 0;
- int d3 = 0;
- int e1;
- int e2;
- int e3;
- int e4;
- int pad = 0;
-
- d1 = dData[ i ];
- if( ( i + 1 ) < dData.length )
- {
- d2 = dData[ i + 1 ];
- if( ( i + 2 ) < dData.length )
- {
- d3 = dData[ i + 2 ];
- }
- else
- {
- pad = 1;
- }
- }
- else
- {
- pad = 2;
- }
-
- e1 = ALPHASET[ ( d1 & I6O2 ) >> 2 ];
- e2 = ALPHASET[ ( d1 & O6I2 ) << 4 | ( d2 & I4O4 ) >> 4 ];
- e3 = ALPHASET[ ( d2 & O4I4 ) << 2 | ( d3 & I2O6 ) >> 6 ];
- e4 = ALPHASET[ ( d3 & O2I6 ) ];
-
- eData[ eIndex++ ] = (byte) e1;
- eData[ eIndex++ ] = (byte) e2;
- eData[ eIndex++ ] = ( pad < 2 ) ? (byte) e3 : (byte) '=';
- eData[ eIndex++ ] = ( pad < 1 ) ? (byte) e4 : (byte) '=';
-
- if( pad > 0 && !includePadding )
- {
- byte[] neweData = new byte[ eData.length - pad ];
- System.arraycopy( eData, 0, neweData, 0, eIndex - pad );
- eData = neweData;
- }
- }
-
- return eData;
- }
-
- private final static int[] CODES = new int[ 256 ];
-
- static
- {
- for( int i = 0; i < CODES.length; i++ )
- {
- CODES[ i ] = 64;
- }
- for( int i = 0; i < ALPHASET.length; i++ )
- {
- CODES[ ALPHASET[ i ] ] = i;
- }
- }
-
- /**
- * Decodes a base64 byte array into a byte array.
- * <p>
- *
- * @param eData byte array to decode.
- *
- * @return decoded byte array.
- *
- * @throws java.lang.IllegalArgumentException
- * thrown if the given byte array was not valid com.sun.syndication.io.impl.Base64 encoding.
- */
- public static byte[] decode( byte[] eData )
- {
- if( eData == null )
- {
- throw new IllegalArgumentException( "Cannot decode null" );
- }
- byte[] cleanEData = eData.clone();
- int cleanELength = 0;
- for( byte anEData : eData )
- {
- if( anEData < 256 && CODES[ anEData ] < 64 )
- {
- cleanEData[ cleanELength++ ] = anEData;
- }
- }
-
- int dLength = ( cleanELength / 4 ) * 3;
- switch( cleanELength % 4 )
- {
- case 3:
- dLength += 2;
- break;
- case 2:
- dLength++;
- break;
- }
-
- byte[] dData = new byte[ dLength ];
- int dIndex = 0;
- for( int i = 0; i < eData.length; i += 4 )
- {
- if( ( i + 3 ) > eData.length )
- {
- throw new IllegalArgumentException(
- "byte array is not a valid base64 encoding"
- );
- }
- int e1 = CODES[ cleanEData[ i ] ];
- int e2 = CODES[ cleanEData[ i + 1 ] ];
- int e3 = CODES[ cleanEData[ i + 2 ] ];
- int e4 = CODES[ cleanEData[ i + 3 ] ];
- dData[ dIndex++ ] = (byte) ( ( e1 << 2 ) | ( e2 >> 4 ) );
- if( dIndex < dData.length )
- {
- dData[ dIndex++ ] = (byte) ( ( e2 << 4 ) | ( e3 >> 2 ) );
- }
- if( dIndex < dData.length )
- {
- dData[ dIndex++ ] = (byte) ( ( e3 << 6 ) | ( e4 ) );
- }
- }
- return dData;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/c5ca22d3/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
index 88167af..5d67aa2 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
@@ -23,6 +23,7 @@ import java.io.ObjectInputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -46,7 +47,6 @@ import org.apache.zest.api.type.MapType;
import org.apache.zest.api.type.Serialization;
import org.apache.zest.api.type.ValueCompositeType;
import org.apache.zest.api.type.ValueType;
-import org.apache.zest.api.util.Base64Encoder;
import org.apache.zest.api.util.Dates;
import org.apache.zest.api.value.ValueBuilder;
import org.apache.zest.api.value.ValueDescriptor;
@@ -814,7 +814,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
throws Exception
{
byte[] bytes = inputString.getBytes( UTF_8 );
- bytes = Base64Encoder.decode( bytes );
+ bytes = Base64.getDecoder().decode( bytes );
Object result;
try (ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream( bytes ) ))
{
http://git-wip-us.apache.org/repos/asf/zest-java/blob/c5ca22d3/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
index 5f5314f..42ad151 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
@@ -22,6 +22,7 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -36,7 +37,6 @@ import org.apache.zest.api.composite.CompositeInstance;
import org.apache.zest.api.entity.EntityComposite;
import org.apache.zest.api.entity.EntityReference;
import org.apache.zest.api.property.Property;
-import org.apache.zest.api.util.Base64Encoder;
import org.apache.zest.api.util.Dates;
import org.apache.zest.api.value.ValueComposite;
import org.apache.zest.api.value.ValueDescriptor;
@@ -513,7 +513,7 @@ public abstract class ValueSerializerAdapter<OutputType>
{
out.writeUnshared( object );
}
- byte[] bytes = Base64Encoder.encode( bout.toByteArray(), true );
+ byte[] bytes = Base64.getEncoder().encode( bout.toByteArray() );
return new String( bytes, UTF_8 );
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/c5ca22d3/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/User.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/User.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/User.java
index 71d71b3..ba34822 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/User.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/User.java
@@ -21,11 +21,11 @@ package org.apache.zest.sample.forum.data.entity;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
import org.apache.zest.api.entity.EntityComposite;
import org.apache.zest.api.mixin.Mixins;
import org.apache.zest.api.property.Immutable;
import org.apache.zest.api.property.Property;
-import org.apache.zest.api.util.Base64Encoder;
/**
* TODO
@@ -59,8 +59,7 @@ public interface User
md.update( password.getBytes( "UTF-8" ) );
byte raw[] = md.digest();
- String hash = new String( Base64Encoder.encode( raw, false ) );
- return hash;
+ return Base64.getEncoder().encodeToString( raw );
}
catch( NoSuchAlgorithmException e )
{
[2/2] zest-java git commit: Fixed a reference in documentation to the
now gone Specification class.
Posted by ni...@apache.org.
Fixed a reference in documentation to the now gone Specification class.
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/4dabe578
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/4dabe578
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/4dabe578
Branch: refs/heads/develop
Commit: 4dabe5781cd73463526951b70b097c2f0b45b320
Parents: c5ca22d
Author: Niclas Hedhman <ni...@hedhman.org>
Authored: Mon Dec 14 10:37:08 2015 +0800
Committer: Niclas Hedhman <ni...@hedhman.org>
Committed: Mon Dec 14 10:42:58 2015 +0800
----------------------------------------------------------------------
core/io/src/docs/io.txt | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zest-java/blob/4dabe578/core/io/src/docs/io.txt
----------------------------------------------------------------------
diff --git a/core/io/src/docs/io.txt b/core/io/src/docs/io.txt
index 3abd508..dc68a99 100644
--- a/core/io/src/docs/io.txt
+++ b/core/io/src/docs/io.txt
@@ -179,18 +179,9 @@ as every 1000 items. This may not be what you think a ProgressLog should look li
how you can combine the general principles found in the Zestâ„¢ Core API package.
== How to write a filter specification? ==
-The filter transform takes a specification implementation which has a very simple method, isSatisfiedBy() (read more
-about that in <<core-functional>>.
-
-[snippet,java]
---------------
-source=core/functional/src/main/java/org/apache/zest/functional/Specification.java
-tag=specification
---------------
-
-The only thing that the implementation need to do is return *true* or *false* for whether the item passed in is within
-the limits of the Specification. Let's say that you have a IntegerRangeSpecification, which could then be implemented
-as
+The filter transform takes a regular java.util.function.Predicate as an argument, where the implementation needs to
+return *true* or *false* for whether the item passed in is within
+the limits. Let's say that you have a IntegerRangeSpecification, which could then be implemented as
[snippet,java]
--------------