Home » Archives for Ilias Tsagklis » Page 28

Author Archives: Ilias Tsagklis

Avatar photo
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Create memory mapped file

Bipartite Graph

This is an example of how to create a memory mapped file in Java. Doing reads and writes of data using Java NIO Channels implies that you should : Create a File object to encapsulate an actual file in the file system Create a random access file stream (read only, read-write). To do so you must first create a RandomAccessFile ...

Read More »

Create shared file lock on file

Bipartite Graph

In this example we shall show you how to create a shared file lock in Java. Creating shared file locks using Java NIO Channels implies that you should : Create a File object to encapsulate an actual file in the file system that you want to lock to Create a random access file stream (read-write). To do so you must ...

Read More »

Write/Append to File with ByteBuffer

Bipartite Graph

With this is example we are going to demonstrate how to write/append data to a file in Java using a ByteBuffer. Particularly we are going to read data from a source file and append them to the destination file. In short what we do is the following : Create a File object to encapsulate an actual file in the file ...

Read More »

Use ByteBuffer to store Strings

Bipartite Graph

This is an example of how to store Strings using a ByteBuffer in Java. In order to use a ByteBuffer to store Strings in Java we have to : Allocate a new ByteBuffer and set its size to a number large enough in order to avoid buffer to overflow when putting bytes to it Use the asCharBuffer() API method so ...

Read More »

Put byte into ByteBuffer

Bipartite Graph

This is an example of how to put bytes into a ByteBuffer in Java. Additionally we will demonstrate several of ByteBuffer‘s API methods in order to share some light on how to randomly write data to it.                 package com.javacodegeeks.snippets.core; import java.nio.ByteBuffer; public class PutByteIntoByteBuffer { public static void main(String[] args) { // ...

Read More »

Convert between ByteBuffer and byte array

Bipartite Graph

With this example we are going to demonstrate how to convert between ByteBuffers and byte arrays. In short, to make a conversion between a ByteBuffer and a byte array you should: Create a byte array and wrap it into a ByteBuffer. The buffer’s capacity and limit will be the array’s length and its position will be zero. Retrieve the bytes ...

Read More »

Encrypt/Decrypt a file using DES

Bipartite Graph

In this example we shall show you how to encrypt/decrypt a file using DES. To encrypt and decrypt a file using the Data Encryption Standard Algorithm, one should perform the following steps: Create a KeyGenerator for the DES algorithm and generate a secret key. Create an IvParameterSpec object, which is an implementation of the AlgorithmParameterSpec Interface, a specification of cryptographic ...

Read More »

Encrypt/Decrypt with salt

Bipartite Graph

This is an example of how to encrypt and decrypt using a salt. The salt is random data very often used in cryptography as additional input to a hash function. Doing encryption and decryption of a String with a salt implies that you should: Read an initial String. Generate random bytes to be placed in the salt. Create a sun.misc.BASE64Decoder ...

Read More »

SHA-1 hash function example

Bipartite Graph

With this example we are going to demonstrate how to make a SHA-1 hash function example. The Secure Hash Algorithm is a family of cryptographic functions. In short, to compute the hash value of a String with the SHA-1 algorithm, you should: Create a MessageDigest Object that implements the SHA-1 algorithm, using the getInstance(String algorithm) API method. Reset the MessageDigest ...

Read More »

Simple symmetric key encrypt/decrypt

Bipartite Graph

In this example we shall show you how to encrypt and decrypt using a symmetric key. In the case of a symmetric key, the same key is used to encrypt and decrypt the data. Because both parties have the same key, the decryption essentially is performed by reversing some part of the encryption process. To encrypt and decrypt a String ...

Read More »