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


Java IOUtils.close方法代码示例

本文整理汇总了Java中com.gemstone.gemfire.internal.util.IOUtils.close方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.close方法的具体用法?Java IOUtils.close怎么用?Java IOUtils.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.gemstone.gemfire.internal.util.IOUtils的用法示例。


在下文中一共展示了IOUtils.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readStatus

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Reads the GemFire JMX Agent's status from the status file (.agent.ser) in it's working directory.
 * <p/>
 * @return a Status object containing the state persisted to the .agent.ser file in the working directory
 * and representing the status of the Agent
 * @throws IOException if the status file was unable to be read.
 * @throws RuntimeException if the class of the object written to the .agent.ser file is not of type Status.
 */
protected Status readStatus() throws IOException {
  FileInputStream fileIn = null;
  ObjectInputStream objectIn = null;

  try {
    fileIn = new FileInputStream(new File(workingDirectory, statusFileName));
    objectIn = new ObjectInputStream(fileIn);
    this.status = (Status) objectIn.readObject();
    return this.status;
  }
  catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
  }
  finally {
    IOUtils.close(objectIn);
    IOUtils.close(fileIn);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:AgentLauncher.java

示例2: writeStatus

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Sets the status of the GemFire JMX Agent by serializing a <code>Status</code> object to a status file
 * in the Agent's working directory.
 * <p/>
 * @param status the Status object representing the state of the Agent process to persist to disk.
 * @return the written Status object.
 * @throws IOException if the Status could not be successfully persisted to disk.
 */
public Status writeStatus(final Status status) throws IOException {
  FileOutputStream fileOut = null;
  ObjectOutputStream objectOut = null;

  try {
    fileOut = new FileOutputStream(new File(workingDirectory, statusFileName));
    objectOut = new ObjectOutputStream(fileOut);
    objectOut.writeObject(status);
    objectOut.flush();
    this.status = status;
    return this.status;
  }
  finally {
    IOUtils.close(objectOut);
    IOUtils.close(fileOut);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:26,代码来源:AgentLauncher.java

示例3: readPid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Reads in the pid from the specified file.
 * 
 * @param pidFile the file containing the pid of the process to stop
 * 
 * @return the process id (pid) contained within the pidFile
 * 
 * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer
 * @throws IOException if unable to read from the specified file
 * @throws NumberFormatException if the pid file does not contain a parsable integer
 */
private static int readPid(final File pidFile) throws IOException {
  BufferedReader fileReader = null;
  String pidValue = null;

  try {
    fileReader = new BufferedReader(new FileReader(pidFile));
    pidValue = fileReader.readLine();

    final int pid = Integer.parseInt(pidValue);

    if (pid < 1) {
      throw new IllegalArgumentException("Invalid pid '" + pid + "' found in " + pidFile);
    }

    return pid;
  }
  catch (NumberFormatException e) {
    throw new IllegalArgumentException("Invalid pid '" + pidValue + "' found in " + pidFile);
  }
  finally {
    IOUtils.close(fileReader);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:LocalProcessController.java

示例4: readPid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Reads in the pid from the specified file.
 * 
 * @param pidFile the file containing the pid of the process to stop
 * 
 * @return the process id (pid) contained within the pidFile
 * 
 * @throws IllegalArgumentException if the pid in the pidFile is not a positive integer
 * @throws IOException if unable to read from the specified file
 * @throws NumberFormatException if the pid file does not contain a parsable integer
 */
private static int readPid(File pidFile) throws IOException {
  BufferedReader fileReader = null;
  String pidValue = null;

  try {
    fileReader = new BufferedReader(new FileReader(pidFile));
    pidValue = fileReader.readLine();

    final int pid = Integer.parseInt(pidValue);

    if (pid < 1) {
      throw new IllegalArgumentException("Invalid pid '" + pid + "' found in " + pidFile.getCanonicalPath());
    }

    return pid;
  }
  catch (NumberFormatException e) {
    throw new IllegalArgumentException("Invalid pid '" + pidValue + "' found in " + pidFile.getCanonicalPath());
  }
  finally {
    IOUtils.close(fileReader);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:ProcessControllerFactory.java

示例5: writeStatus

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Sets the status of a cache server by serializing a <code>Status</code>
 * instance to a file in the server's working directory.
 */
public void writeStatus(final Status s) throws IOException {
  final File statusFile = new File(workingDir, statusName);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  ObjectOutput out = null;
  RandomAccessFile raFile = null;
  try {
    if (!statusFile.exists()) {
      NativeCalls.getInstance().preBlow(statusFile.getAbsolutePath(), 2048,
          true);
    }
    raFile = new RandomAccessFile(statusFile.getAbsolutePath(), "rw");
    out = new ObjectOutputStream(bos);
    out.writeObject(s);
    raFile.write(bos.toByteArray());
  } finally {
    if (out != null) {
      try {
        out.close();
      } catch (IOException ignore) {
      }
    }
    bos.close();
    IOUtils.close(raFile);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:30,代码来源:CacheServerLauncher.java

示例6: writePid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
public static void writePid(final File pidFile, final int pid) throws IOException {
	Assert.isTrue(pidFile != null && (pidFile.isFile() || pidFile.createNewFile()), String.format(
			"The file system pathname (%1$s) in which the PID will be written is not a valid file!", pidFile));

	Assert.isTrue(pid > 0, String.format("The PID value (%1$d) must greater than 0!", pid));

	PrintWriter fileWriter = new PrintWriter(new BufferedWriter(new FileWriter(pidFile, false), 16), true);

	try {
		fileWriter.println(pid);
	}
	finally {
		pidFile.deleteOnExit();
		IOUtils.close(fileWriter);
	}
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:gemfire,代码行数:17,代码来源:ProcessUtils.java

示例7: stop

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
/**
 * Deregisters everything this Agent registered and releases the MBeanServer.
 */
public void stop() {
  try {
    this.logWriter.info(LocalizedStrings.AgentImpl_STOPPING_JMX_AGENT);
    this.logWriter.shuttingDown();

    // stop the GemFire Distributed System
    stopDistributedSystem();

    // stop all JMX Adaptors and Connectors...
    stopHttpAdaptor();
    stopRMIConnectorServer();
    memberInfoWithStatsMBean = null;
    stopSnmpAdaptor();

    // release the MBeanServer for cleanup...
    MBeanUtil.stop();
    mBeanServer = null;

    // remove the register shutdown hook which disconnects the Agent from the Distributed System upon JVM shutdown
    removeShutdownHook();

    this.logWriter.info(LocalizedStrings.AgentImpl_AGENT_HAS_STOPPED);
  }
  finally {
    if (this.logFileOutputStream != null) {
      this.logWriter.closingLogFile();
      IOUtils.close(this.logFileOutputStream);
    }
    LogWriterImpl.cleanUpThreadGroups(); // bug35388 - logwriters accumulate, causing mem leak
  }

}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:36,代码来源:AgentImpl.java

示例8: readErrorStream

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
protected String readErrorStream(final Process process) throws IOException {
  final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
  final StringBuilder message = new StringBuilder();

  for (String line = reader.readLine(); line != null; line = reader.readLine()) {
    message.append(line);
    message.append(StringUtils.LINE_SEPARATOR);
  }

  IOUtils.close(reader);

  return message.toString();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:14,代码来源:LauncherLifecycleCommands.java

示例9: loadPropertiesFromURL

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
private static Map<String, String> loadPropertiesFromURL(URL gfSecurityPropertiesUrl) {
  Map<String, String> propsMap = Collections.emptyMap();

  if (gfSecurityPropertiesUrl != null) {
    InputStream inputStream = null;
    try {
      Properties props = new Properties();
      inputStream = gfSecurityPropertiesUrl.openStream();
      props.load(inputStream);
      if (!props.isEmpty()) {
        Set<String> jmxSpecificProps = new HashSet<String>();
        propsMap = new LinkedHashMap<String, String>();
        Set<Entry<Object, Object>> entrySet = props.entrySet();
        for (Entry<Object, Object> entry : entrySet) {

          String key = (String)entry.getKey();
          if (key.endsWith(DistributionConfig.JMX_SSL_PROPS_SUFFIX)) {
            key = key.substring(0, key.length() - DistributionConfig.JMX_SSL_PROPS_SUFFIX.length());
            jmxSpecificProps.add(key);

            propsMap.put(key, (String)entry.getValue());
          } else if (!jmxSpecificProps.contains(key)) {// Prefer properties ending with "-jmx" over default SSL props.
            propsMap.put(key, (String)entry.getValue());
          }
        }
        props.clear();
        jmxSpecificProps.clear();
      }
    } catch (IOException io) {
      throw new RuntimeException(CliStrings.format(
          CliStrings.CONNECT__MSG__COULD_NOT_READ_CONFIG_FROM_0,
              CliUtil.decodeWithDefaultCharSet(gfSecurityPropertiesUrl.getPath())), io);
    } finally {
      IOUtils.close(inputStream);
    }
  }
  return propsMap;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:39,代码来源:ShellCommands.java

示例10: readPid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
public static int readPid(final File pidFile) throws IOException {
  BufferedReader reader = null;
  try {
    reader = new BufferedReader(new FileReader(pidFile));
    return Integer.parseInt(reader.readLine());
  }
  finally {
    IOUtils.close(reader);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:11,代码来源:ProcessUtils.java

示例11: getMemberId

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort, final String memberName)
  throws Exception
{
  JMXConnector connector = null;

  try {
    connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
      "service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));

    final MBeanServerConnection connection = connector.getMBeanServerConnection();

    final ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");

    final QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));

    final Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);

    assertNotNull(objectNames);
    assertEquals(1, objectNames.size());

    //final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" + memberName);
    final ObjectName objectName = objectNames.iterator().next();

    //System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName, objectName);

    return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
  }
  finally {
    IOUtils.close(connector);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:LauncherLifecycleCommandsDUnitTest.java

示例12: writePid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
protected static void writePid(final File pidFile, final int pid) throws IOException {
  assertTrue("The PID file must actually exist!", pidFile != null && pidFile.isFile());
  final FileWriter writer = new FileWriter(pidFile, false);
  writer.write(String.valueOf(pid));
  writer.write("\n");
  writer.flush();
  IOUtils.close(writer);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:9,代码来源:LauncherLifecycleCommandsDUnitTest.java

示例13: writePid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
protected void writePid(final File pidFile, final int pid) throws IOException {
  final FileWriter fileWriter = new FileWriter(pidFile, false);
  fileWriter.write(String.valueOf(pid));
  fileWriter.write("\n");
  fileWriter.flush();
  IOUtils.close(fileWriter);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:8,代码来源:LauncherLifecycleCommandsJUnitTest.java

示例14: readPid

import com.gemstone.gemfire.internal.util.IOUtils; //导入方法依赖的package包/类
protected int readPid(final File pidFile) throws IOException {
  BufferedReader reader = null;
  try {
    reader = new BufferedReader(new FileReader(pidFile));
    return Integer.parseInt(StringUtils.trim(reader.readLine()));
  }
  finally {
    IOUtils.close(reader);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:11,代码来源:AbstractLauncherDUnitTestCase.java


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