Skip to content

Commit

Permalink
Better IO Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 7, 2013
1 parent f30404a commit c576cba
Showing 1 changed file with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/**
* Used to perform Addon installation/registration operations.
*
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* @author <a href="mailto:koen.aers@gmail.com">Koen Aers</a>
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
Expand Down Expand Up @@ -90,13 +90,13 @@ public static boolean isApiCompatible(CharSequence runtimeVersion, AddonId entry

/**
* This method only returns true if:
*
*
* - The major version of addonApiVersion is equal to the major version of runtimeVersion AND
*
*
* - The minor version of addonApiVersion is less or equal to the minor version of runtimeVersion
*
*
* - The addonApiVersion is null
*
*
* @param runtimeVersion a version in the format x.x.x
* @param addonApiVersion a version in the format x.x.x
*/
Expand Down Expand Up @@ -166,10 +166,16 @@ public boolean deploy(AddonId addon, List<AddonDependency> dependencies, List<Fi
dep.attribute(ATTR_OPTIONAL, dependency.isOptional());
}

FileOutputStream fos = new FileOutputStream(descriptor);
Streams.write(XMLParser.toXMLInputStream(addonXml), fos);
fos.close();

FileOutputStream fos = null;
try
{
fos = new FileOutputStream(descriptor);
Streams.write(XMLParser.toXMLInputStream(addonXml), fos);
}
finally
{
Streams.closeQuietly(fos);
}
return true;
}
}
Expand Down Expand Up @@ -200,9 +206,16 @@ public boolean disable(final AddonId addon)
Node child = installed.getSingle("addon@" + ATTR_NAME + "=" + addon.getName() + "&"
+ ATTR_VERSION + "=" + addon.getVersion());
installed.removeChild(child);
FileOutputStream outStream = new FileOutputStream(registryFile);
Streams.write(XMLParser.toXMLInputStream(installed), outStream);
outStream.close();
FileOutputStream outStream = null;
try
{
outStream = new FileOutputStream(registryFile);
Streams.write(XMLParser.toXMLInputStream(installed), outStream);
}
finally
{
Streams.closeQuietly(outStream);
}
return true;
}
catch (IOException e)
Expand Down Expand Up @@ -237,7 +250,16 @@ public boolean enable(AddonId addon)
installed.getOrCreate("addon@" + ATTR_NAME + "=" + (addon.getName() == null ? "" : addon.getName()) +
"&" + ATTR_VERSION + "=" + addon.getVersion())
.attribute(ATTR_API_VERSION, (addon.getApiVersion() == null ? "" : addon.getApiVersion()));
Streams.write(XMLParser.toXMLInputStream(installed), new FileOutputStream(registryFile));
FileOutputStream destination = null;
try
{
destination = new FileOutputStream(registryFile);
Streams.write(XMLParser.toXMLInputStream(installed), destination);
}
finally
{
Streams.closeQuietly(destination);
}

return true;
}
Expand Down Expand Up @@ -306,9 +328,16 @@ public File getAddonDescriptor(AddonId addon)
descriptorFile.delete();
descriptorFile.createNewFile();

FileOutputStream stream = new FileOutputStream(descriptorFile);
Streams.write(XMLParser.toXMLInputStream(XMLParser.parse("<addon/>")), stream);
stream.close();
FileOutputStream stream = null;
try
{
stream = new FileOutputStream(descriptorFile);
Streams.write(XMLParser.toXMLInputStream(XMLParser.parse("<addon/>")), stream);
}
finally
{
Streams.closeQuietly(stream);
}
}
return descriptorFile;
}
Expand Down Expand Up @@ -417,14 +446,15 @@ public File getRepositoryRegistryFile()
{
registryFile.createNewFile();

FileOutputStream out = new FileOutputStream(registryFile);
FileOutputStream out = null;
try
{
out = new FileOutputStream(registryFile);
Streams.write(XMLParser.toXMLInputStream(XMLParser.parse("<installed></installed>")), out);
}
finally
{
out.close();
Streams.closeQuietly(out);
}
}
}
Expand Down

1 comment on commit c576cba

@lincolnthree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks George.

Please sign in to comment.