当前位置: 首页>>代码示例>>Java>>正文


Java WillClose类代码示例

本文整理汇总了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);
}
 
开发者ID:google,项目名称:caja,代码行数:22,代码来源:CharProducer.java

示例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();
  }
}
 
开发者ID:google,项目名称:caja,代码行数:18,代码来源:FetchedData.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:IJAXBWriter.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:SettingsPersistenceProperties.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:SettingsPersistenceXML.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-css,代码行数:34,代码来源:CSSReaderDeclarationList.java

示例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();
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:29,代码来源:SuppressionDecorator.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-css,代码行数:35,代码来源:CSSReader.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:MicroReader.java

示例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;
        }
    }
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:26,代码来源:BugResolutionLoader.java

示例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);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:IO.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:29,代码来源:XMLMapHandler.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:30,代码来源:XMLListHandler.java

示例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();
        }
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:20,代码来源:Filter.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:CodepointIteratorReadableByteChannel.java


注:本文中的javax.annotation.WillClose类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。