本文整理汇总了Java中com.gemstone.gemfire.internal.util.IOUtils类的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IOUtils类属于com.gemstone.gemfire.internal.util包,在下文中一共展示了IOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
/**
* After parsing the command line arguments, spawn the Java VM that will host the GemFire JMX Agent.
*/
public void start(final String[] args) throws Exception {
final Map<String, Object> options = getStartOptions(args);
workingDirectory = IOUtils.tryGetCanonicalFileElseGetAbsoluteFile((File) options.get(DIR));
// verify that any GemFire JMX Agent process has been properly shutdown and delete any remaining status files...
verifyAndClearStatus();
// start the GemFire JMX Agent process...
runCommandLine(options, buildCommandLine(options));
// wait for the GemFire JMX Agent process to complete startup and begin running...
// it is also possible the Agent process may fail to start, so this should not wait indefinitely unless
// the status file was not successfully written to
pollAgentUntilRunning();
System.exit(0);
}
示例2: server
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
/**
* Starts the GemFire JMX Agent "server" process with the given command line arguments.
*/
public void server(final String[] args) throws Exception {
final Map<String, Object> options = getServerOptions(args);
// make the process a UNIX daemon if possible
String errMsg = makeDaemon();
workingDirectory = IOUtils.tryGetCanonicalFileElseGetAbsoluteFile((File) options.get(DIR));
Status status = createStatus(this.basename, STARTING, OSProcess.getId());
status.msg = errMsg;
writeStatus(status);
Agent agent = startAgentVM((Properties) options.get(AGENT_PROPS), status);
// periodically check and see if the JMX Agent has been told to stop
pollAgentForPendingShutdown(agent);
}
示例3: getStopOptions
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
/**
* Extracts configuration information for stopping a agent based on the
* contents of the command line. This method can also be used with getting
* the status of a agent.
*/
protected Map<String, Object> getStopOptions(final String[] args) throws Exception {
final Map<String, Object> options = new HashMap<String, Object>();
options.put(DIR, IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(new File(".")));
for (final String arg : args) {
if (arg.equals("stop") || arg.equals("status")) {
// expected
}
else if (arg.startsWith("-dir=")) {
processDirOption(options, arg.substring("-dir=".length()));
}
else {
throw new Exception(LocalizedStrings.AgentLauncher_UNKNOWN_ARGUMENT_0.toLocalizedString(arg));
}
}
return options;
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: convert
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
/**
* Converts the array of Resources into a 2-dimensional byte array containing content from each Resource.
* The 2-dimensional byte array format is used by Gfsh and the GemFire Manager to transmit file data.
* <p/>
* @param resources an array of Spring Resource objects to convert into the 2-dimensional byte array format.
* @return a 2-dimensional byte array containing the content of each Resource.
* @throws IllegalArgumentException if the filename of a Resource was not specified.
* @throws IOException if an I/O error occurs reading the contents of a Resource!
* @see org.springframework.core.io.Resource
*/
public static byte[][] convert(final Resource... resources) throws IOException {
if (resources != null) {
final List<byte[]> fileData = new ArrayList<byte[]>(resources.length * 2);
for (final Resource resource : resources) {
if (StringUtils.isBlank(resource.getFilename())) {
throw new IllegalArgumentException(String.format("The filename of Resource (%1$s) must be specified!",
resource.getDescription()));
}
fileData.add(resource.getFilename().getBytes());
fileData.add(IOUtils.toByteArray(resource.getInputStream()));
}
return fileData.toArray(new byte[fileData.size()][]);
}
return new byte[0][];
}
示例7: getToolsJarPath
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
protected String getToolsJarPath() throws AttachAPINotFoundException {
String toolsJarPathname = null;
if (!SystemUtils.isMacOSX()) {
toolsJarPathname = IOUtils.appendToPath(JAVA_HOME, "lib", "tools.jar");
if (!IOUtils.isExistingPathname(toolsJarPathname)) {
// perhaps the java.home System property refers to the JRE ($JAVA_HOME/jre)...
final String JDK_HOME = new File(JAVA_HOME).getParentFile().getPath();
toolsJarPathname = IOUtils.appendToPath(JDK_HOME, "lib", "tools.jar");
}
try {
IOUtils.verifyPathnameExists(toolsJarPathname);
}
catch (IOException e) {
throw new AttachAPINotFoundException(getAttachAPINotFoundMessage());
}
}
return toolsJarPathname;
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: testReadInternal
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
@Test
public void testReadInternal() throws IOException {
final String expectedInputMessageBody = "Expected content of the HTTP input message body!";
final HttpInputMessage mockInputMessage = mockContext.mock(HttpInputMessage.class, "HttpInputMessage");
mockContext.checking(new Expectations() {{
oneOf(mockInputMessage).getBody();
will(returnValue(new ByteArrayInputStream(IOUtils.serializeObject(expectedInputMessageBody))));
}});
final SerializableObjectHttpMessageConverter converter = new SerializableObjectHttpMessageConverter();
final Serializable obj = converter.readInternal(String.class, mockInputMessage);
assertTrue(obj instanceof String);
assertEquals(expectedInputMessageBody, obj);
}
示例12: testConvertFileData
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
@Test
public void testConvertFileData() throws IOException {
final String[] filenames = { "/path/to/file1.ext", "/path/to/another/file2.ext" };
final String[] fileContent = { "This is the contents of file 1.", "This is the contents of file 2." };
final List<byte[]> fileData = new ArrayList<byte[]>(2);
for (int index = 0; index < filenames.length; index++) {
fileData.add(filenames[index].getBytes());
fileData.add(fileContent[index].getBytes());
}
final Resource[] resources = ConvertUtils.convert(fileData.toArray(new byte[fileData.size()][]));
assertNotNull(resources);
assertEquals(filenames.length, resources.length);
for (int index = 0; index < resources.length; index++) {
assertEquals(filenames[index], resources[index].getFilename());
assertEquals(fileContent[index], new String(IOUtils.toByteArray(resources[index].getInputStream())));
}
}
示例13: testConvertResource
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
@Test
public void testConvertResource() throws IOException {
final Resource[] resources = {
createResource("/path/to/file1.txt", "Contents of file1.".getBytes()),
createResource("/path/to/file2.txt", "Contents of file2.".getBytes())
};
final byte[][] fileData = ConvertUtils.convert(resources);
assertNotNull(fileData);
assertEquals(resources.length * 2, fileData.length);
for (int index = 0; index < fileData.length; index += 2) {
assertEquals(resources[index / 2].getFilename(), new String(fileData[index]));
assertEquals(new String(IOUtils.toByteArray(resources[index / 2].getInputStream())), new String(fileData[index + 1]));
}
}
示例14: testSetAndGetWorkingDirectory
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
@Test
public void testSetAndGetWorkingDirectory() {
final Builder builder = new Builder();
assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(null));
assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(""));
assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(" "));
assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(System.getProperty("user.dir")));
assertEquals(System.getProperty("user.dir"), builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(System.getProperty("java.io.tmpdir")));
assertEquals(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(new File(System.getProperty("java.io.tmpdir"))),
builder.getWorkingDirectory());
assertSame(builder, builder.setWorkingDirectory(null));
assertEquals(AbstractLauncher.DEFAULT_WORKING_DIRECTORY, builder.getWorkingDirectory());
}
示例15: getBackupDir
import com.gemstone.gemfire.internal.util.IOUtils; //导入依赖的package包/类
/**
* Locates a previously created backup directory associated with an online backup counter.
* @param counter a ParRegBB.onlineBackupNumber
* @throws TestException a backup directory could not be located or was malformed (not a directory or contains no children or too many children).
*/
private static String getBackupDir(long counter) {
File backupDir = new File("backup_" + counter);
if(!backupDir.exists()) {
throw new TestException("PersistenceUtil#getBackupDir: Backup directory " + backupDir.getName() + " does not exist.");
}
File[] files = backupDir.listFiles();
if((null == files) || (files.length != 1)) {
throw new TestException("PersistenceUtil#getBackupDir: Backup directory " + backupDir.getName() + " is malformed or is not a directory");
}
return IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(files[0]).getAbsolutePath();
}