Enabling Parsing and Processing of PHP code in Files With .html Extensions for GoDaddy.com Hosting Accounts

There are times when a web master will want to have the default file extension for a given website stay consistent regardless of how the files are preprocessed on the server-side or what server-side scripting language is being used.

To set up your GoDaddy.com 4GH, Linux hosted account to parse PHP code in .html files, do the following:

  1. Log in to your account.
  2. Go to the control panel for the web site in question.
  3. In the control panel click on
Continue reading “Enabling Parsing and Processing of PHP code in Files With .html Extensions for GoDaddy.com Hosting Accounts”

Cloned VMware CentOS6 Server and "device eth0 does not seem to be present, delaying initialization" Error

Recently, I cloned a vmware install of CentOS6 and after firing up the clone and trying to start networking received the error: “device eth0 does not seem to be present, delaying initialization”

It turns out that the NIC on the cloned machine was being renamed and registered to eth1.

To list the current ethn devices:

# ls /sys/class/net
eth1 lo

There is a device manager, udev, which stores the settings from the NIC of the vm prior to the cloning → Continue reading “Cloned VMware CentOS6 Server and "device eth0 does not seem to be present, delaying initialization" Error”

Java: Capitalize the First Letter in a String

A seemingly trivial task, but worth jotting down for future reference.

String sourceString = “this is some string”;
String convertedString = String.format(“%s%s”, Character.toUpperCase(sourceString.charAt(0)), sourceString.substring(1));
Continue reading “Java: Capitalize the First Letter in a String”

Java: How To Use RandomAccessFile and FileChannel to Write to a Specific Location in a File

If there is ever a need to write bytes to a specific location to an existing file, here is an example of how to use the RandomAccessFile and FileChannel Java classes to do so:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Will write bytes to the beginning of an existing file.
 *
 * @author Ryan Chapin
 */
public class RandomAccessFileTest {

    public static void main(String[] args) {

        // Generate input string and the → Continue reading “Java: How To Use RandomAccessFile and FileChannel to Write to a Specific Location in a File”

Using a ProcessBuilder to Execute an OS Level Command and Properly Read the Exit Code from a Java Process

There are many a situation where a developer will want to execute an OS level command in another process and read not only the standard out (stdout), and standard error (sterr), but also the exit code returned from the process.

To do so, utilize the ProcessBuilder class along with a helper class (ProcessWrapper) that will provide the ability to set a timeout for the process and read the exit code in a separate thread.

Following is an example and the → Continue reading “Using a ProcessBuilder to Execute an OS Level Command and Properly Read the Exit Code from a Java Process”

Dynamically Instantiating Classes in Java

Edited 2021-02-08 to reflect API changes for Java 11.

There are a number of cases when you may not know exactly what class you will be instantiating and want to be able to dynamically instantiate specific classes based on a configuration file or a condition during runtime.

To do so, you will need to define a parent class, abstract class, or interface for your classes and can then use the following code as a guide.

Given the following class definitions:→ Continue reading “Dynamically Instantiating Classes in Java”

Preserving File Permissions When Copying Files with Ant

If you want to retain the file permissions of a file that you copy with ant you must use the <exec> command instead of? <copy>.

So, instead of:

<copy file=”${source.file}” tofile=”${dest.path}/${dest.file}” overwrite=”true”/>

Use:

<exec executable=”cp”>
? <arg value=”-pf”/>
? <arg value=”${source.file}”/>
? <arg value=”${dest.path}/${dest.file}”/>
</exec>
Continue reading “Preserving File Permissions When Copying Files with Ant”

java.lang.OutOfMemoryError: unable to create new native thread Exception When Using SmbFileInputStream

I am writing an application that copies files from a Samba share using the JCIFC Java CIFS Client Library (which, btw, is a very helpful, widely used, and well developed project).

As usual I am under the gun to get something up and running so I do not have the luxury to explore all of the details as much as I would like. My application gets a directory listing of a Samba share and then spawns a new thread for → Continue reading “java.lang.OutOfMemoryError: unable to create new native thread Exception When Using SmbFileInputStream”

Adding a ShutdownHook to a Java Program to Enable Clean Exit on CTRL-C

Often times I will be building a Java program that will either be run from a command-line or as a system service.  In most cases, during development, I’ll be running it directly from the command-line and will want to kill it by pressing control c on the keyboard.

When I do that I want to make sure that my program cleanly exits, closing any open files, socket connections, database connects, or what have you.

To do so, you must invoke → Continue reading “Adding a ShutdownHook to a Java Program to Enable Clean Exit on CTRL-C”