This commit is contained in:
Looly 2024-01-09 23:15:52 +08:00
parent 64c1dc554b
commit ebf1632f36
6 changed files with 31 additions and 30 deletions

View File

@ -13,7 +13,8 @@
package org.dromara.hutool.core.lang.wrapper;
/**
* 简单包装对象
* 简单包装对象<br>
* 通过继承此类可以直接使用被包装的对象用于简化和统一封装
*
* @param <T> 被包装对象类型
* @author looly

View File

@ -49,17 +49,17 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
@Override
public String getAlgorithmName() {
return getRaw().getAlgorithm();
return this.raw.getAlgorithm();
}
@Override
public int getBlockSize() {
return getRaw().getBlockSize();
return this.raw.getBlockSize();
}
@Override
public int getOutputSize(final int len) {
return getRaw().getOutputSize(len);
return this.raw.getOutputSize(len);
}
@Override
@ -82,7 +82,7 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
* @throws InvalidKeyException 无效key
*/
public void init(final int mode, final JceParameters jceParameters) throws InvalidAlgorithmParameterException, InvalidKeyException {
final javax.crypto.Cipher cipher = getRaw();
final javax.crypto.Cipher cipher = this.raw;
if (null != jceParameters.parameterSpec) {
if (null != jceParameters.random) {
cipher.init(mode, jceParameters.key, jceParameters.parameterSpec, jceParameters.random);
@ -101,7 +101,7 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
@Override
public int process(final byte[] in, final int inOff, final int len, final byte[] out, final int outOff) {
try {
return getRaw().update(in, inOff, len, out, outOff);
return this.raw.update(in, inOff, len, out, outOff);
} catch (final ShortBufferException e) {
throw new CryptoException(e);
}
@ -110,7 +110,7 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
@Override
public int doFinal(final byte[] out, final int outOff) {
try {
return getRaw().doFinal(out, outOff);
return this.raw.doFinal(out, outOff);
} catch (final Exception e) {
throw new CryptoException(e);
}
@ -119,7 +119,7 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
@Override
public byte[] processFinal(final byte[] data) {
try {
return getRaw().doFinal(data);
return this.raw.doFinal(data);
} catch (final Exception e) {
throw new CryptoException(e);
}

View File

@ -253,7 +253,7 @@ public class Digester extends SimpleWrapper<MessageDigest> implements Serializab
// 加盐在末尾自动忽略空盐值
result = doDigest(data, this.salt);
} else if (ArrayUtil.isNotEmpty(this.salt)) {
final MessageDigest digest = getRaw();
final MessageDigest digest = this.raw;
// 加盐在中间
digest.update(data, 0, this.saltPosition);
digest.update(this.salt);

View File

@ -41,29 +41,29 @@ public class BCMacEngine extends SimpleWrapper<Mac> implements MacEngine {
@Override
public void update(final byte[] in, final int inOff, final int len) {
getRaw().update(in, inOff, len);
this.raw.update(in, inOff, len);
}
@Override
public byte[] doFinal() {
final byte[] result = new byte[getMacLength()];
getRaw().doFinal(result, 0);
this.raw.doFinal(result, 0);
return result;
}
@Override
public void reset() {
getRaw().reset();
this.raw.reset();
}
@Override
public int getMacLength() {
return getRaw().getMacSize();
return this.raw.getMacSize();
}
@Override
public String getAlgorithm() {
return getRaw().getAlgorithmName();
return this.raw.getAlgorithmName();
}
/**

View File

@ -70,32 +70,32 @@ public class JCEMacEngine extends SimpleWrapper<Mac> implements MacEngine {
@Override
public void update(final byte[] in) {
getRaw().update(in);
this.raw.update(in);
}
@Override
public void update(final byte[] in, final int inOff, final int len) {
getRaw().update(in, inOff, len);
this.raw.update(in, inOff, len);
}
@Override
public byte[] doFinal() {
return getRaw().doFinal();
return this.raw.doFinal();
}
@Override
public void reset() {
getRaw().reset();
this.raw.reset();
}
@Override
public int getMacLength() {
return getRaw().getMacLength();
return this.raw.getMacLength();
}
@Override
public String getAlgorithm() {
return getRaw().getAlgorithm();
return this.raw.getAlgorithm();
}
/**

View File

@ -71,52 +71,52 @@ public class DSWrapper extends SimpleWrapper<DataSource> implements DataSource,
@Override
public PrintWriter getLogWriter() throws SQLException {
return getRaw().getLogWriter();
return this.raw.getLogWriter();
}
@Override
public void setLogWriter(final PrintWriter out) throws SQLException {
getRaw().setLogWriter(out);
this.raw.setLogWriter(out);
}
@Override
public void setLoginTimeout(final int seconds) throws SQLException {
getRaw().setLoginTimeout(seconds);
this.raw.setLoginTimeout(seconds);
}
@Override
public int getLoginTimeout() throws SQLException {
return getRaw().getLoginTimeout();
return this.raw.getLoginTimeout();
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return getRaw().getParentLogger();
return this.raw.getParentLogger();
}
@Override
public <T> T unwrap(final Class<T> iface) throws SQLException {
return getRaw().unwrap(iface);
return this.raw.unwrap(iface);
}
@Override
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
return getRaw().isWrapperFor(iface);
return this.raw.isWrapperFor(iface);
}
@Override
public Connection getConnection() throws SQLException {
return getRaw().getConnection();
return this.raw.getConnection();
}
@Override
public Connection getConnection(final String username, final String password) throws SQLException {
return getRaw().getConnection(username, password);
return this.raw.getConnection(username, password);
}
@Override
public void close() {
final DataSource ds = getRaw();
final DataSource ds = this.raw;
if (ds instanceof AutoCloseable) {
IoUtil.closeQuietly((AutoCloseable) ds);
}