1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dishevelled.piccolo.tilemap.io.impl;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30
31 import java.net.URL;
32
33 import org.dishevelled.piccolo.tilemap.AbstractTileMap;
34
35 import org.dishevelled.piccolo.tilemap.io.TileMapReader;
36
37
38
39
40
41
42
43 public abstract class AbstractTileMapReader
44 implements TileMapReader
45 {
46
47 @Override
48 public final AbstractTileMap read(final File file) throws IOException
49 {
50 if (file == null)
51 {
52 throw new IllegalArgumentException("file must not be null");
53 }
54 InputStream inputStream = null;
55 try
56 {
57 inputStream = new FileInputStream(file);
58 return read(inputStream);
59 }
60 catch (IOException e)
61 {
62 throw e;
63 }
64 finally
65 {
66 closeQuietly(inputStream);
67 }
68 }
69
70 @Override
71 public final AbstractTileMap read(final URL url) throws IOException
72 {
73 if (url == null)
74 {
75 throw new IllegalArgumentException("url must not be null");
76 }
77 InputStream inputStream = null;
78 try
79 {
80 inputStream = url.openStream();
81 return read(inputStream);
82 }
83 catch (IOException e)
84 {
85 throw e;
86 }
87 finally
88 {
89 closeQuietly(inputStream);
90 }
91 }
92
93
94
95
96
97
98 protected static final void closeQuietly(final InputStream inputStream)
99 {
100 try
101 {
102 inputStream.close();
103 }
104 catch (Exception e)
105 {
106
107 }
108 }
109 }