@SuppressWarnings("unchecked") private T unserialize(byte[] bytes) { try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInput in = new ObjectInputStream(bis)) { return (T) in.readObject(); } catch (ClassNotFoundException | IOException ex) { throw new EidIllegalStateException("20161219:163039", ex); } } }
private byte[] decode(CharSequence charSequence) { try { return Base64 .getUrlDecoder() .decode(charSequence.toString()); } catch (IllegalArgumentException ex) { throw new EidIllegalStateException("20180509:132318", ex); } }
private byte[] serialize(T target) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos)) { out.writeObject(target); out.flush(); return bos.toByteArray(); } catch (IOException e) { throw new EidIllegalStateException("20161219:162734", e); } }
<I, T extends I> T newLazy(Class<I> cls, String eid) { try { return newLazyUnsafely(cls, eid); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException ex) { throw new EidIllegalStateException("20180517:110633", ex); } }
private <T extends Predicate<InspectionPoint>> T createPredicateFalseProxy( Class<T> contractClass) { InvocationHandler handler = (proxy, method, args) -> false; @SuppressWarnings("unchecked") Class<T> proxyClass = (Class<T>) java.lang.reflect.Proxy.getProxyClass( Thread.currentThread().getContextClassLoader(), contractClass ); try { return proxyClass .getConstructor(InvocationHandler.class) .newInstance(handler); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new EidIllegalStateException("20180515:180325", e); } } }
private String getClassNameRepr(Serializable type) { if (type instanceof Class) { return classNameEncoder.getReprForClassName( Class.class.cast(type).getName() ); } throw new EidIllegalStateException( new Eid("20180509:143750"), "Unsupported type: %s", type.getClass() ); }
@Override public String serialize(Serializable serializable) { if (serializable instanceof Long) { return Long.toString((Long) serializable, RADIX); } try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos)) { out.writeObject(serializable); out.flush(); return Base64.getUrlEncoder() .withoutPadding() .encodeToString(bos.toByteArray()); } catch (IOException e) { throw new EidIllegalStateException("20180509:143244", e); } }
private void initiate() { try { getEncrypt(); getDecrypt(); } catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { throw new EidIllegalStateException("20140131:003954", ex); } }
@Override public Optional<PetContract> findPetByReference(EntityReference reference) { if (reference.getType() != Pet.class) { throw new SecurityException( new EidIllegalStateException(new Eid("20180511:212223")) ); } Optional<Pet> pet = petsGateway .findByReference(reference::getReference) .fetch(PetFetchProfile.WITH_OWNER); return pet.map(this::petAsContract); }
private Cipher tryToInit(int cmode) throws NoSuchAlgorithmException, NoSuchPaddingException { Cipher cipher; try { cipher = getAesCipher(); cipher.init(cmode, getKey()); return cipher; } catch (InvalidKeyException ex) { mode = Mode.LIMITED; cipherInst = null; log.warn( "Using LIMITED cipher mode (AES 128 bits). Install Java Cryptography " + "Extension (JCE) Unlimited Strength Jurisdiction Policy Files for better " + "encryption (AES 256 bits)" ); try { cipher = getAesCipher(); cipher.init(cmode, getKey()); return cipher; } catch (InvalidKeyException ex1) { throw new EidIllegalStateException("20140131:003922", ex1); } } }
@RequestMapping(value = "/edit", method = RequestMethod.POST) public String edit(Model model, @ModelAttribute(FORM_OBJECT) EditPetForm form) { EntityReference reference = entityReferenceMapper .map(form.getReference()) .orElseThrow(() -> new EidIllegalStateException(new Eid("20180514:223428"))); PetContract pet = getPetFromForm(form.getData()); UpdatePetRequest request = new UpdatePetRequest( reference, pet ); Consumer<UpdatePetResponse> response = updatePetUseCase.updatePet(request); EditPetPresenter presenter = new EditPetPresenter( form.getReference(), pet, racePresenter ); response.accept(presenter); if (presenter.isSuccessful()) { return "redirect:../"; } else { return formHanding(model, presenter); } }