To ensure the resource is automatically closedtags/8.1.0.alpha1
@@ -85,9 +85,8 @@ public class SASSAddonImportFileCreator { | |||
LocationInfo info = ClassPathExplorer | |||
.getAvailableWidgetSetsAndStylesheets(); | |||
try { | |||
PrintStream printStream = new PrintStream( | |||
new FileOutputStream(addonImports)); | |||
try (PrintStream printStream = new PrintStream( | |||
new FileOutputStream(addonImports))) { | |||
printStream.println("/* " + ADDON_IMPORTS_FILE_TEXT + " */"); | |||
@@ -352,15 +352,16 @@ public class ClassesSerializableTest { | |||
private Collection<String> findClassesInJar(File file) throws IOException { | |||
Collection<String> classes = new ArrayList<>(); | |||
JarFile jar = new JarFile(file); | |||
Enumeration<JarEntry> e = jar.entries(); | |||
while (e.hasMoreElements()) { | |||
JarEntry entry = e.nextElement(); | |||
if (entry.getName().endsWith(".class")) { | |||
String nameWithoutExtension = entry.getName() | |||
.replaceAll("\\.class", ""); | |||
String className = nameWithoutExtension.replace('/', '.'); | |||
classes.add(className); | |||
try (JarFile jar = new JarFile(file)) { | |||
Enumeration<JarEntry> e = jar.entries(); | |||
while (e.hasMoreElements()) { | |||
JarEntry entry = e.nextElement(); | |||
if (entry.getName().endsWith(".class")) { | |||
String nameWithoutExtension = entry.getName() | |||
.replaceAll("\\.class", ""); | |||
String className = nameWithoutExtension.replace('/', '.'); | |||
classes.add(className); | |||
} | |||
} | |||
} | |||
return classes; |
@@ -22,22 +22,23 @@ public class SimpleMultiPartInputStreamTest { | |||
protected void checkBoundaryDetection(byte[] input, String boundary, | |||
byte[] expected) throws Exception { | |||
ByteArrayInputStream bais = new ByteArrayInputStream(input); | |||
SimpleMultiPartInputStream smpis = new SimpleMultiPartInputStream(bais, | |||
boundary); | |||
ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); | |||
int outbyte; | |||
try { | |||
while ((outbyte = smpis.read()) != -1) { | |||
resultStream.write(outbyte); | |||
try (SimpleMultiPartInputStream smpis = new SimpleMultiPartInputStream(bais, | |||
boundary)) { | |||
ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); | |||
int outbyte; | |||
try { | |||
while ((outbyte = smpis.read()) != -1) { | |||
resultStream.write(outbyte); | |||
} | |||
} catch (IOException e) { | |||
throw new IOException( | |||
e.getMessage() + "; expected " + new String(expected) | |||
+ " but got " + resultStream.toString()); | |||
} | |||
if (!Arrays.equals(expected, resultStream.toByteArray())) { | |||
throw new Exception("Mismatch: expected " + new String(expected) | |||
+ " but got " + resultStream.toString()); | |||
} | |||
} catch (IOException e) { | |||
throw new IOException( | |||
e.getMessage() + "; expected " + new String(expected) | |||
+ " but got " + resultStream.toString()); | |||
} | |||
if (!Arrays.equals(expected, resultStream.toByteArray())) { | |||
throw new Exception("Mismatch: expected " + new String(expected) | |||
+ " but got " + resultStream.toString()); | |||
} | |||
} | |||
@@ -45,15 +45,14 @@ public class EditableTableLeak extends TestBase { | |||
} | |||
public static long getSize(Object object) { | |||
ByteCountNullOutputStream os = new ByteCountNullOutputStream(); | |||
ObjectOutputStream oos; | |||
try { | |||
oos = new ObjectOutputStream(os); | |||
try (ByteCountNullOutputStream os = new ByteCountNullOutputStream()) { | |||
ObjectOutputStream oos = new ObjectOutputStream(os); | |||
oos.writeObject(object); | |||
return os.getBytes(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
return 0; | |||
} | |||
return os.getBytes(); | |||
} | |||
} | |||
@@ -942,16 +942,17 @@ public abstract class AbstractTB3Test extends ParallelTest { | |||
String hostName = ce.getAddressOfRemoteServer().getHost(); | |||
int port = ce.getAddressOfRemoteServer().getPort(); | |||
HttpHost host = new HttpHost(hostName, port); | |||
DefaultHttpClient client = new DefaultHttpClient(); | |||
URL sessionURL = new URL("http://" + hostName + ":" + port | |||
+ "/grid/api/testsession?session=" + d.getSessionId()); | |||
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest( | |||
"POST", sessionURL.toExternalForm()); | |||
HttpResponse response = client.execute(host, r); | |||
JsonObject object = extractObject(response); | |||
URL myURL = new URL(object.getString("proxyId")); | |||
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) { | |||
return myURL.getHost(); | |||
try (DefaultHttpClient client = new DefaultHttpClient()) { | |||
URL sessionURL = new URL("http://" + hostName + ":" + port | |||
+ "/grid/api/testsession?session=" + d.getSessionId()); | |||
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest( | |||
"POST", sessionURL.toExternalForm()); | |||
HttpResponse response = client.execute(host, r); | |||
JsonObject object = extractObject(response); | |||
URL myURL = new URL(object.getString("proxyId")); | |||
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) { | |||
return myURL.getHost(); | |||
} | |||
} | |||
} catch (Exception e) { | |||
e.printStackTrace(); |