Giter VIP home page Giter VIP logo

java-utilities's Introduction

Java Utilities Module

Codacy Badge Build Status

Contains helper classes that I find useful every now and then.

Classes Summary

ImageCompressionUtils

Used to compress image files to JPEG format using the desired quality for the compressed image.

Sample Usage

// Compression quality (value >= 0 and <= 1)
final float quality = 0.35f;

// Compressing to bytes from source image bytes
byte[] compressed = ImageCompressionUtils.compressImage(sourceBytes, quality);

ImageCompressor

A Thread-Safe Object-Oriented wrapper for the ImageCompressionUtils utility class with Base64 and method chaining support.

Sample Usage

// Creating a new instance and setting the compressed image quality
ImageCompressor mImageCompressor = new ImageCompressor().setCompressedImageQuality(0.75f);

// Compressing an image to byte array
byte[] compressed = mImageCompressor.setSourceImage(sourceBytes).compressImageToByteArray();

// Modifying the compressed image quality, and compressing a new image to Base64
String compressedBase64 = mImageCompressor.setCompressedImageQuality(0.35f)
					  .setSourceImage(sourceBytesTwo)
  					  .compressImageToBase64();

ConcurrentCache

Cache implementation with a periodic memory clean up process for objects that haven't been accessed for a specified period of time.

Sample Usage

long cleanUpInterval = 100; // milliseconds
long objectTTL = 2000; // milliseconds
int cacheSize = 25;

private ConcurrentCache<Integer, String> mCache = new ConcurrentCache<>(objectTTL, cleanUpInterval, cacheSize);

PBKDF2Helper

Wrapper class to help manipulate PBKDF2 parameters and generate keys.

Sample Usage

// Using the builder
PBKDF2Helper mHelper = new PBKDF2Helper.Builder(KeySize.KEY_256)
                .iterations(Iterations.MEDIUM)
                .saltSize(SaltSize.SALT_128)
                .build();

// Generating a key
byte[] key = mHelper.createKeyFromPassword(PASSWORD);

// Getting configurations for storage
String config = mHelper.getPbkdf2Configurations();

// Creation using the configurations string
PBKDF2Helper mHelper = new PBKDF2Helper.Builder(config).build();

FileEncryptorAES

Used to encrypt files using AES with PBKDF2.

Sample Usage

// Using factory method for creation
FileEncryptorAES mEncryptor = FileEncryptorAES.createEncryptorWithHighSecurityParams(PASSWORD);

// Setting the progress monitor
mEncryptor.setProgressMonitor((int progress) -> System.out.println());

// Encryption
BufferedInputStream mInputStream = new BufferedInputStream(new FileInputStream(mSourceFile));
BufferedOutputStream mOutputStream = new BufferedOutputStream(new FileOutputStream(mTargetFile));
mEncryptor.encrypt(mInputStream, mOutputstream);

FileDecryptorAES

Used to decrypt files encrypted with FileEncryptorAES.

Sample Usage

// Creation
FileDecryptorAES mDecryptor = new FileDecryptorAES(PASSWORD);

// Setting the progress monitor
mDecryptor.setProgressMonitor((int progress) -> System.out.println());

// Decryption
BufferedInputStream mInputStream = new BufferedInputStream(new FileInputStream(mSourceFile));
BufferedOutputStream mOutputStream = new BufferedOutputStream(new FileOutputStream(mTargetFile));
mDecryptor.decrypt(mInputStream, mOutputStream);   

Secure Preferences

Provides an AES encryption layer over the java.util.prefs.Preferences class.

Sample Usage

// Setting up the prefs
SecurePreferences mPreferences = new SecurePreferencesImpl("test-node", "pa$$word");

// Storing a string value
String str = "test-data";
mPreferences.putString("string", str);

// Getting the value
Optional<String> mOptional = mPreferences.getString("string");
if(mOptional.isPresent()){
    String loaded = mOptional.get();
}

CloneUtils

Used to deep clone objects that implements the Serializable interface. (Any objects used by the class must also implement Serializable).

Sample Usage

SomeObject clone = CloneUtils.deepClone(origin, SomeObject.class);

LuhnChecker

Used to check card numbers using the Luhn formula.

Sample Usage

boolean isValid = LuhnChecker.checkNumberValidity("4532136548631895");

Developed By

License

Copyright 2017 Hussain Al-Derry

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.

java-utilities's People

Contributors

codacy-badger avatar hussainderry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mouamleh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.