本文整理汇总了Java中javax.annotation.WillClose类的典型用法代码示例。如果您正苦于以下问题:Java WillClose类的具体用法?Java WillClose怎么用?Java WillClose使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WillClose类属于javax.annotation包,在下文中一共展示了WillClose类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* @param r read and closed as a side-effect of this operation.
*/
public static CharProducer create(@WillClose Reader r, FilePosition pos)
throws IOException {
int limit = 0;
char[] buf = new char[4096];
try {
for (int n = 0; (n = r.read(buf, limit, buf.length - limit)) > 0;) {
limit += n;
if (limit == buf.length) {
char[] newBuf = new char[buf.length * 2];
System.arraycopy(buf, 0, newBuf, 0, limit);
buf = newBuf;
}
}
} finally {
r.close();
}
return new CharProducerImpl(buf, limit, pos);
}
示例2: readStream
import javax.annotation.WillClose; //导入依赖的package包/类
protected static byte[] readStream(@WillClose InputStream is)
throws IOException {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] barr = new byte[4096];
int totalLen = 0;
for (int n; (n = is.read(barr)) > 0;) {
if ((totalLen += n) > MAX_RESPONSE_SIZE_BYTES) {
throw new IOException("Response too large");
}
buffer.write(barr, 0, n);
}
return buffer.toByteArray();
} finally {
is.close();
}
}
示例3: write
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* Write the passed object to an {@link OutputStream}.
*
* @param aObject
* The object to be written. May not be <code>null</code>.
* @param aOS
* The output stream to write to. Will always be closed. May not be
* <code>null</code>.
* @return {@link ESuccess}
*/
@Nonnull
default ESuccess write (@Nonnull final JAXBTYPE aObject, @Nonnull @WillClose final OutputStream aOS)
{
try
{
if (USE_JAXB_CHARSET_FIX)
{
return write (aObject, SafeXMLStreamWriter.create (aOS, getXMLWriterSettings ()));
}
return write (aObject, TransformResultFactory.create (aOS));
}
finally
{
// Needs to be manually closed
StreamHelper.close (aOS);
}
}
示例4: readSettings
import javax.annotation.WillClose; //导入依赖的package包/类
@Nonnull
public ISettings readSettings (@Nonnull @WillClose final InputStream aIS)
{
ValueEnforcer.notNull (aIS, "InputStream");
// Create the settings object
final ISettings aSettings = m_aSettingsFactory.apply (getReadSettingsName ());
// Read the properties file from the input stream
final NonBlockingProperties aProps = PropertiesHelper.loadProperties (aIS);
if (aProps != null)
for (final Map.Entry <String, String> aEntry : aProps.entrySet ())
aSettings.putIn (aEntry.getKey (), aEntry.getValue ());
return aSettings;
}
示例5: writeSettings
import javax.annotation.WillClose; //导入依赖的package包/类
@Nonnull
public ESuccess writeSettings (@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS)
{
ValueEnforcer.notNull (aSettings, "Settings");
ValueEnforcer.notNull (aOS, "OutputStream");
try
{
// Inside try so that OS is closed
ValueEnforcer.notNull (aSettings, "Settings");
// No event manager invocation on writing
final SettingsMicroDocumentConverter <T> aConverter = new SettingsMicroDocumentConverter <> (m_aSettingsFactory);
final IMicroDocument aDoc = new MicroDocument ();
aDoc.appendChild (aConverter.convertToMicroElement (GenericReflection.uncheckedCast (aSettings),
getWriteNamespaceURI (),
getWriteElementName ()));
// auto-closes the stream
return MicroWriter.writeToStream (aDoc, aOS, m_aXWS);
}
finally
{
StreamHelper.close (aOS);
}
}
示例6: isValidCSS
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* Check if the passed reader can be resembled to valid CSS content. This is
* accomplished by fully parsing the CSS each time the method is called. This
* is similar to calling
* {@link #readFromStream(IHasInputStream, Charset, ECSSVersion)} and checking
* for a non-<code>null</code> result.
*
* @param aReader
* The reader to use. May not be <code>null</code>.
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @return <code>true</code> if the CSS is valid according to the version,
* <code>false</code> if not
*/
public static boolean isValidCSS (@Nonnull @WillClose final Reader aReader, @Nonnull final ECSSVersion eVersion)
{
ValueEnforcer.notNull (aReader, "Reader");
ValueEnforcer.notNull (eVersion, "Version");
try
{
final CSSCharStream aCharStream = new CSSCharStream (aReader);
final CSSNode aNode = _readStyleDeclaration (aCharStream,
eVersion,
getDefaultParseErrorHandler (),
new DoNothingCSSParseExceptionCallback ());
return aNode != null;
}
finally
{
StreamHelper.close (aReader);
}
}
示例7: processPackageList
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* @param rawIn
* @throws IOException
*/
private void processPackageList(@WillClose Reader rawIn) throws IOException {
try {
BufferedReader in = new BufferedReader(rawIn);
while (true) {
String s = in.readLine();
if (s == null)
break;
s = s.trim();
if (s.length() == 0)
continue;
String packageName = s.substring(1).trim();
if (s.charAt(0) == '+') {
check.add(packageName);
dontCheck.remove(packageName);
} else if (s.charAt(0) == '-') {
dontCheck.add(packageName);
check.remove(packageName);
} else
throw new IllegalArgumentException("Can't parse " + category + " filter line: " + s);
}
} finally {
rawIn.close();
}
}
示例8: isValidCSS
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* Check if the passed reader can be resembled to valid CSS content. This is
* accomplished by fully parsing the CSS each time the method is called. This
* is similar to calling
* {@link #readFromStream(IHasInputStream, Charset, ECSSVersion)} and checking
* for a non-<code>null</code> result.
*
* @param aReader
* The reader to use. May not be <code>null</code>.
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @return <code>true</code> if the CSS is valid according to the version,
* <code>false</code> if not
*/
public static boolean isValidCSS (@Nonnull @WillClose final Reader aReader, @Nonnull final ECSSVersion eVersion)
{
ValueEnforcer.notNull (aReader, "Reader");
ValueEnforcer.notNull (eVersion, "Version");
try
{
final CSSCharStream aCharStream = new CSSCharStream (aReader);
final CSSNode aNode = _readStyleSheet (aCharStream,
eVersion,
getDefaultParseErrorHandler (),
new DoNothingCSSParseExceptionCallback (),
false);
return aNode != null;
}
finally
{
StreamHelper.close (aReader);
}
}
示例9: readMicroXML
import javax.annotation.WillClose; //导入依赖的package包/类
@Nullable
public static IMicroDocument readMicroXML (@WillClose @Nullable final InputStream aIS,
@Nullable final ISAXReaderSettings aSettings)
{
if (aIS == null)
return null;
try
{
return readMicroXML (InputSourceFactory.create (aIS), aSettings);
}
finally
{
StreamHelper.close (aIS);
}
}
示例10: parseDocument
import javax.annotation.WillClose; //导入依赖的package包/类
@CheckForNull
private Document parseDocument(@WillClose InputStream is) {
try {
if (builder == null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
}
return builder.parse(is);
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
} catch (SAXException e) {
FindbugsPlugin.getDefault().logException(e, "Failed to parse xml file");
return null;
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Failed to read the xml file");
return null;
} finally {
try {
is.close();
} catch (IOException e) {
assert true;
}
}
}
示例11: readAll
import javax.annotation.WillClose; //导入依赖的package包/类
public static byte[] readAll(@WillClose InputStream in, int size) throws IOException {
try {
if (size == 0)
throw new IllegalArgumentException();
byte[] result = new byte[size];
int pos = 0;
while (true) {
int sz;
while ((sz = in.read(result, pos, size - pos)) > 0) {
pos += sz;
}
if (pos < size)
return Arrays.copyOf(result, pos);
int nextByte = in.read();
if (nextByte == -1)
return result;
size = size * 2 + 500;
result = Arrays.copyOf(result, size);
result[pos++] = (byte) nextByte;
}
} finally {
close(in);
}
}
示例12: writeMap
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* Write the passed map to the passed output stream using the predefined XML
* layout.
*
* @param aMap
* The map to be written. May not be <code>null</code>.
* @param aOS
* The output stream to write to. The stream is closed independent of
* success or failure. May not be <code>null</code>.
* @return {@link ESuccess#SUCCESS} when everything went well,
* {@link ESuccess#FAILURE} otherwise.
*/
@Nonnull
public static ESuccess writeMap (@Nonnull final Map <String, String> aMap, @Nonnull @WillClose final OutputStream aOS)
{
ValueEnforcer.notNull (aMap, "Map");
ValueEnforcer.notNull (aOS, "OutputStream");
try
{
final IMicroDocument aDoc = createMapDocument (aMap);
return MicroWriter.writeToStream (aDoc, aOS, XMLWriterSettings.DEFAULT_XML_SETTINGS);
}
finally
{
StreamHelper.close (aOS);
}
}
示例13: writeList
import javax.annotation.WillClose; //导入依赖的package包/类
/**
* Write the passed collection to the passed output stream using the
* predefined XML layout.
*
* @param aCollection
* The map to be written. May not be <code>null</code>.
* @param aOS
* The output stream to write to. The stream is closed independent of
* success or failure. May not be <code>null</code>.
* @return {@link ESuccess#SUCCESS} when everything went well,
* {@link ESuccess#FAILURE} otherwise.
*/
@Nonnull
public static ESuccess writeList (@Nonnull final Collection <String> aCollection,
@Nonnull @WillClose final OutputStream aOS)
{
ValueEnforcer.notNull (aCollection, "Collection");
ValueEnforcer.notNull (aOS, "OutputStream");
try
{
final IMicroDocument aDoc = createListDocument (aCollection);
return MicroWriter.writeToStream (aDoc, aOS, XMLWriterSettings.DEFAULT_XML_SETTINGS);
}
finally
{
StreamHelper.close (aOS);
}
}
示例14: writeEnabledMatchersAsXML
import javax.annotation.WillClose; //导入依赖的package包/类
public void writeEnabledMatchersAsXML(@WillClose OutputStream out) throws IOException {
XMLOutput xmlOutput = new OutputStreamXMLOutput(out);
try {
xmlOutput.beginDocument();
xmlOutput.openTag("FindBugsFilter");
Iterator<Matcher> i = childIterator();
while (i.hasNext()) {
Matcher child = i.next();
if (!disabled.containsKey(child)) {
child.writeXML(xmlOutput, false);
}
}
xmlOutput.closeTag("FindBugsFilter");
} finally {
xmlOutput.finish();
}
}
示例15: _convert
import javax.annotation.WillClose; //导入依赖的package包/类
@Nonnull
private static ByteBuffer _convert (@Nonnull @WillClose final ReadableByteChannel aChannel) throws IOException
{
try
{
final ByteBuffer buf = ByteBuffer.allocate (1024);
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ();
final WritableByteChannel aOutChannel = Channels.newChannel (aBAOS);
while (aChannel.read (buf) > 0)
{
buf.flip ();
aOutChannel.write (buf);
}
return ByteBuffer.wrap (aBAOS.toByteArray ());
}
finally
{
StreamHelper.close (aChannel);
}
}