Home » Archives for Ilias Tsagklis » Page 40

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.

List contents of zip file

Bipartite Graph

In this example we shall show you how to get the list of the contents of a zip file, with ZipFile that is used to read entries from a zip file. To get the files that a zip file contains one should perform the following steps: Create a new ZipFile and open it for reading. Get the Enumeration of the ...

Read More »

Get zip entry compression method

Bipartite Graph

This is an example of how to get the ZipEntry Compression method. The compression method of a ZipEntry can be either STORED for uncompressed entries, or DEFLATED for compressed (deflated) entries. Getting the compression method of the ZipEntry implies that you should: Create a new ZipFile to read a zip file with the given name. Get the Enumeration of the ...

Read More »

Compress Objects example

Bipartite Graph

With this example we are going to demonstrate how to compress and expand an Object. We have implemented the ObjectCompressionUtil Class, that extends the Serializable class and has a parameter that is the generic type of the serializable object to be compressed. The class consists of two methods. The compressObject(final T objectToCompress, final OutputStream outstream) takes the object to compress and ...

Read More »

CountDownLatch example of a more general wait/notify mechanism

Bipartite Graph

In this example we shall show you how to create a CountDownLatch of a more general wait/notify mechanism. We have implemented a method, that is testWaitNotify(). The steps of the method are described below: It creates an Object, to be the mutex. It creates a new Thread, that in its run() method acquires the object, using the synchronized() statement. Although ...

Read More »

Blocking Queue example of limited connection pool

Bipartite Graph

private BlockingQueue<Connection> pool = new ArrayBlockingQueue<Connection>(10); private AtomicInteger connCount = new AtomicInteger(); public Connection getConnection() { Connection conn = pool.poll(5, TimeUnit.SECONDS); if (conn == null) { synchronized (connCount) { if (connCount.get() < 10) { conn = getNewConnection(); pool.offer(conn); connCount.incrementAndGet(); } } if (conn == null) { throw new ConnUnavailException(); } else { return conn; } } } Related Article: Java ...

Read More »

Reentrant Lock example of a task runner

Bipartite Graph

With this example we are going to demonstrate how to implement a ReentrantLock of a task runner. The ReentrantLock is a reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities. The custom Class that have implemented is called TaskRunner and consists of the ...

Read More »

Semaphores example limiting URL connections

Bipartite Graph

In this example we shall show you how to use a Semaphore for limiting URL connections. We have implemented a class, ConnectionLimiter that uses a Semaphore and is described below: It creates a new Semaphore with a given number of permits. It implements a method, URLConnection acquire(URL url). The method acquires a permit from this semaphore, blocking until one is ...

Read More »

Store preferences to user space

Bipartite Graph

This is an example of how to store Preferences to user space. The Preferences class allows applications to store and retrieve user and system preference and configuration data. Storing Preferences to user space implies that you should: Get the root preference node for the calling user, using userRoot() API method of Preferences. Get the named preference for the given pathname of the ...

Read More »

Find elements by id with XPath

Bipartite Graph

With this example we are going to demonstrate how to find elements by Id using XPath. The XPath language provides a simple, concise syntax for selecting nodes from an XML document. XPath also provides rules for converting a node in an XML document object model (DOM) tree to a boolean, double, or string value. In short, to find elements by ...

Read More »

Find elements by attributes with XPath

Bipartite Graph

In this example we shall show you how to find elements by attributes using XPath. The XPath language provides a simple, concise syntax for selecting nodes from an XML document. To find elements by attributes using XPath one should perform the following steps: Obtain a new instance of a DocumentBuilderFactory, that is a factory API that enables applications to obtain ...

Read More »