List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeField
public static void writeField(final Object target, final String fieldName, final Object value) throws IllegalAccessException
From source file:com.joyent.manta.serialization.EncryptedMultipartUploadSerializationHelperTest.java
public void canSerializeAndDeserializeUpload() throws IOException { final UUID uploadId = new UUID(0L, 0L); final String path = "/user/stor/myObject"; final String partsDir = "/user/uploads/0/" + uploadId; final ServerSideMultipartUpload inner = new ServerSideMultipartUpload(uploadId, path, partsDir); final EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); final EncryptionState encryptionState = new EncryptionState(encryptionContext); @SuppressWarnings("unchecked") final EncryptedMultipartUpload<ServerSideMultipartUpload> upload = (EncryptedMultipartUpload<ServerSideMultipartUpload>) newUploadInstance( inner, encryptionState);//from ww w .j a v a 2s . c o m Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext); try { FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); } catch (IllegalAccessException e) { throw new AssertionError(e); } final byte[] serializedData = helper.serialize(upload); final EncryptedMultipartUpload<ServerSideMultipartUpload> deserialized = helper.deserialize(serializedData); Assert.assertEquals(upload, deserialized); }
From source file:com.joyent.manta.serialization.EncryptedMultipartManagerSerializationTest.java
public void canSerializeEncryptedServerSideMultipartUpload() throws IOException { final UUID uploadId = new UUID(0L, 0L); final String path = "/user/stor/myObject"; final String partsDir = "/user/uploads/0/" + uploadId; final ServerSideMultipartUpload inner = new ServerSideMultipartUpload(uploadId, path, partsDir); final EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); final EncryptionState encryptionState = new EncryptionState(encryptionContext); Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext);//from www . ja v a 2s.co m try { FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); } catch (IllegalAccessException e) { throw new AssertionError(e); } final EncryptedMultipartUpload<?> upload = newUploadInstance(inner, encryptionState); final byte[] serializedData; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { this.kryo.writeObject(output, upload); output.flush(); serializedData = outputStream.toByteArray(); } try (Input input = new Input(serializedData)) { final EncryptedMultipartUpload<?> actual = kryo.readObject(input, EncryptedMultipartUpload.class); Assert.assertEquals(actual, upload); } }
From source file:com.joyent.manta.serialization.EncryptionStateSerializerTest.java
private EncryptionState newEncryptionStateInstance() { EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); EncryptionState encryptionState = new EncryptionState(encryptionContext); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); Field multipartStreamField = ReflectionUtils.getField(EncryptionState.class, "multipartStream"); Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); Field lastPartAuthWrittenField = ReflectionUtils.getField(EncryptionState.class, "lastPartAuthWritten"); try {// w ww. ja va 2 s. co m FieldUtils.writeField(multipartStreamField, encryptionState, multipartStream); final OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext); FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); FieldUtils.writeField(lastPartAuthWrittenField, encryptionState, true); } catch (ReflectiveOperationException e) { throw new AssertionError(e); } return encryptionState; }
From source file:com.adobe.acs.commons.mcp.impl.ControlledProcessManagerImpl.java
private <T> void copyReferences(T src, T dest) { for (Field f : src.getClass().getDeclaredFields()) { try {//from w w w . j a va2 s . c o m Object srcValue = FieldUtils.readField(f, src, true); if (srcValue != null && FieldUtils.readField(f, dest, true) == null) { FieldUtils.writeField(f, dest, srcValue); } } catch (IllegalAccessException ex) { Logger.getLogger(ControlledProcessManagerImpl.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.thinkbiganalytics.feedmgr.rest.controller.FeedRestController.java
private void updateFeedMetadata(FeedMetadata targetFeedMetadata, FeedMetadata modifiedFeedMetadata, FeedPropertySection feedPropertySection) { AnnotationFieldNameResolver annotationFieldNameResolver = new AnnotationFieldNameResolver( FeedPropertyType.class); List<AnnotatedFieldProperty> list = annotationFieldNameResolver.getProperties(FeedMetadata.class); List<AnnotatedFieldProperty> sectionList = list.stream() .filter(annotatedFieldProperty -> feedPropertySection .equals(((FeedPropertyType) annotatedFieldProperty.getAnnotation()).section())) .collect(Collectors.toList()); sectionList.forEach(annotatedFieldProperty -> { try {/*from w ww . ja v a 2 s . co m*/ Object value = FieldUtils.readField(annotatedFieldProperty.getField(), modifiedFeedMetadata); FieldUtils.writeField(annotatedFieldProperty.getField(), targetFeedMetadata, value); } catch (IllegalAccessException e) { e.printStackTrace(); } }); }
From source file:lineage2.gameserver.scripts.Scripts.java
/** * Method callScripts./* w w w . ja va 2 s.c om*/ * @param caller Player * @param className String * @param methodName String * @param args Object[] * @param variables Map<String,Object> * @return Object */ public Object callScripts(Player caller, String className, String methodName, Object[] args, Map<String, Object> variables) { Object o; Class<?> clazz; clazz = _classes.get(className); if (clazz == null) { _log.error("Script class " + className + " not found!"); return null; } try { o = clazz.newInstance(); } catch (Exception e) { _log.error("Scripts: Failed creating instance of " + clazz.getName(), e); return null; } if ((variables != null) && !variables.isEmpty()) { for (Map.Entry<String, Object> param : variables.entrySet()) { try { FieldUtils.writeField(o, param.getKey(), param.getValue()); } catch (Exception e) { _log.error("Scripts: Failed setting fields for " + clazz.getName(), e); } } } if (caller != null) { try { Field field = null; if ((field = FieldUtils.getField(clazz, "self")) != null) { FieldUtils.writeField(field, o, caller.getRef()); } } catch (Exception e) { _log.error("Scripts: Failed setting field for " + clazz.getName(), e); } } Object ret = null; try { Class<?>[] parameterTypes = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) { parameterTypes[i] = args[i] != null ? args[i].getClass() : null; } ret = MethodUtils.invokeMethod(o, methodName, args, parameterTypes); } catch (NoSuchMethodException nsme) { _log.error("Scripts: No such method " + clazz.getName() + "." + methodName + "()!"); } catch (InvocationTargetException ite) { _log.error("Scripts: Error while calling " + clazz.getName() + "." + methodName + "()", ite.getTargetException()); } catch (Exception e) { _log.error("Scripts: Failed calling " + clazz.getName() + "." + methodName + "()", e); } return ret; }
From source file:org.apache.sshd.common.file.nativefs.ExtendedNativeFileSystemView.java
public ExtendedNativeFileSystemView(String userName, String rootDir, boolean caseInsensitive) { super(userName, caseInsensitive); try {/*from w ww .j a v a 2s. c om*/ FieldUtils.writeField(currDirField, this, Validate.notEmpty(rootDir, "No root dir specified", ArrayUtils.EMPTY_OBJECT_ARRAY)); } catch (IllegalAccessException e) { throw new IllegalStateException( "Failed (" + e.getClass().getSimpleName() + ") to override currDir: " + e.getMessage(), e); } }