package _2_intersection_types;

import java.io.*;

public class Person
{
    public static void main(String[] args) throws IOException
    {
        RandomAccessFile randomAccess = new RandomAccessFile("src/main/resources/person", "rw");
        DataInputStream stream = new DataInputStream(new FileInputStream("src/main/resources/person"));

        Person person = read(randomAccess);
        System.out.println(person);

        person = read(stream);
        System.out.println(person);
    }

    private static <I extends DataInput & Closeable> Person read(I input)
    {
        try
        {
            return new Person(input.readUTF(), input.readInt());
        }
        catch (IOException e)
        {
            e.printStackTrace();
            close(input);
            return null;
        }
    }

    private static void close(Closeable input)
    {
        try
        {
            input.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    public Person(String name, int age)
    {
        this.name = name;
        this.age = age;
    }

    private final String name;
    private final int age;

    public int getAge()
    {
        return age;
    }

    public String getName()
    {
        return name;
    }

    @Override
    public String toString()
    {
        return "Person{" +
            "name='" + name + '\'' +
            ", age=" + age +
            '}';
    }
}

@@ -558,21 +558,22 @@
  read(I 
-input
+source
 )%0A    %7B%0A
@@ -575,32 +575,50 @@
    %7B%0A        try
+(I input = source)
 %0A        %7B%0A     
@@ -776,247 +776,19 @@
     
-close(input);%0A            return null;%0A        %7D%0A    %7D%0A%0A    private static void close(Closeable input)%0A    %7B%0A        try%0A        %7B%0A            input.close();%0A        %7D%0A        catch (IOException e)%0A        %7B%0A            e.printStackTrace()
+return null
 ;%0A  

use java 7 try-with-resources for a cleaner closing approach