In this topic
- Exporting an acknowledgement message from a replica
- Importing the acknowledgement message into the relative replica
- Connect to a geodatabase to host the replica from which you want to export the acknowledgement message. This requires initializing a geodataserver object. Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
- Call the following procedure by pasting it into your application and passing in the following parameters:
sourceGDS
|
The GeoDataServer that you initialized in Step 1. This hosts the replica geodatabase that is the source of the acknowledgement file.
|
replicaName
|
The replicaName parameter takes the name of the replica.
|
outputDirectory
|
The outputDirectory parameter specifies the output location for the acknowledgement file. This location should point to a directory on your local drive. If this folder exists, it will be replaced. If it doesn't exist, it will be created.
|
static void exportAcknowledgement(IGeoDataServer sourceGDS, String replicaName,
String outputDirectory)throws Exception{
// Export the acknowledgement file.
IGDSData gdsData = sourceGDS.exportAcknowledgement(replicaName,
esriGDSTransportType.esriGDSTransportTypeUrl);
/*
* Replace or create the output directory. If directory already exists,
* delete it and create again by copying. Force deletion of folder and
* contents, if they exist.
*/
initializeDirectory(outputDirectory);
// Download the acknowledgement file from the URL to the local output
// directory.
if (gdsData.getTransportType() == esriGDSTransportType.esriGDSTransportTypeUrl){
String fileURL = gdsData.getURL();
URLConnection connection = new URL(fileURL).openConnection();
String fileName = fileURL.substring(fileURL.lastIndexOf('/') + 1);
connection.connect();
InputStream input = connection.getInputStream();
FileOutputStream output = new FileOutputStream(new File(outputDirectory +
File.separator + fileName));
byte[] bytes = new byte[10000];
int actuallyRead = input.read(bytes);
while (actuallyRead != - 1){
output.write(bytes, 0, actuallyRead);
actuallyRead = input.read(bytes);
}
input.close();
output.flush();
output.close();
}
else{
System.out.println("Server is not configured with a virtual directory");
gdsData.getEmbeddedData(); // The file has been embedded because
// there is no output directory set on
// ArcGIS Server.
}
}
private static void initializeDirectory(String outputDirectory){
File directory = new File(outputDirectory);
if (!directory.exists()){
directory.mkdir();
return ;
}
else{
deleteContents(directory);
directory.delete();
directory.mkdir();
}
}
private static void deleteContents(File directory){
File[] contents = directory.listFiles();
for (File file: contents){
if (file.isDirectory())
deleteContents(file);
file.delete();
}
}
- Connect to a geodatabase to host the replica to which you want to import the acknowledgement message. This requires initializing a geodataserver object. Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
- Call the following procedure by pasting it into your application and passing in the following parameters:
targetGDS
|
The geodataserver that you initialized in Step 1. This hosts the replica geodatabase into which you want to import the acknowledgement file.
|
inputDirectory
|
The inputDirectory specifies the location of the acknowledgement file. This location should point to a directory, which holds the acknowledgement file. The function assumes that there is only one file in this directory. If there are more than one file in the inputDirectory, only the first file will be read.
|
static void importAcknowledgement(IGeoDataServer targetGDS, String inputDirectory)
throws Exception{
/* Get the acknowledgement file from the input directory.
It is assumed that the first file in the directory is the acknowledgement file. */
File ackFile = new File(inputDirectory).listFiles()[0];
long size = ackFile.length();
if (size > Integer.MAX_VALUE){
System.out.println("File is larger than anticipated. Aborting.");
return ;
}
byte[] bytes = new byte[(int)size];
FileInputStream inputStream = new FileInputStream(ackFile);
inputStream.reset();
int actuallyRead = inputStream.read(bytes);
while (actuallyRead != - 1){
actuallyRead += inputStream.read(bytes, actuallyRead, bytes.length -
actuallyRead);
}
// Embed the GDSData object.
IGDSData gdsData = new GDSData();
gdsData.setTransportType(esriGDSTransportType.esriGDSTransportTypeEmbedded);
gdsData.setCompressed(false);
gdsData.setEmbeddedData(bytes);
// Import the acknowledgement file.
targetGDS.importAcknowledgement(gdsData);
}
Development licensing | Deployment licensing |
---|---|
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime: Geodatabase Update |