Below is the part of code where we try build Charts for the error
values and exceptions arised for it, by generating Appropriate URL to
each exception and send it to the Google Server to form an Image to
display it on the chart. But before which why do we save all the URL's
in particular .csv file and read them dynamically to form an image?
************************************************************************************************************************************
public class TrendGenerator {
/**
* Fetches error values from the local file system and generates a
appropriate url to create a chart and map those
* error values onto hourly chart.
* @param args
*/
public static void main(String[] args) {
ErrorDataOrganizer organizer = new ErrorDataOrganizer();
ErrorData errorData = organizer.fetchErrorData();
ChartURLGenerator urlGenerator = new ChartURLGenerator();
Map<String, String> exceptionToChartURLMap =
urlGenerator.generateExceptionToChartURLMap(errorData);
FileIOUtil.writeHourlyTrendCSVFile(errorData,
exceptionToChartURLMap);
//----------------Would like to know why they have used this
part---------------------------??????
ChartDownloader downloader = new ChartDownloaderImpl();
downloader.downloadHourlyChartsForExceptionsInList(errorData,
exceptionToChartURLMap);
//----------------------------------------------------------------------------------------------------------------------
}
}
*****************************************************************************************************************
import java.util.Map;
/**
* ChartDownloader Interface that downloads the hourly charts for the
exception list that includes
* the error data and exceptions that map to URl.
*/
public interface ChartDownloader {
void downloadHourlyChartsForExceptionsInList(ErrorData errorData,
Map<String, String> exceptionToChartURLMap);
}
********************************************************************************************************************
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.ReadableByteChannel;
import java.util.List;
import java.util.Map;
/**
* Prepares the hourly chart image by generating and mapping
appropriate url to each exception in the list.
* creates a channel to write the particular image byte by byte from
the external to local system.
*/
public class ChartDownloaderImpl implements ChartDownloader{
/**
* Prepares hourly trend chart images from Google Chart Tools
using Url's generated by passing error values
* and exceptions.And creates channels to write the streams of
bytes of data. And keeps track the number of charts formed.
* @param errorData obtained from ErrorDataOrganizer
* @param exceptionToChartURLMap created in ChartURLGenerator
*/
public void downloadHourlyChartsForExceptionsInList
(ErrorData errorData, Map<String, String>
exceptionToChartURLMap){
try {
List<String> dailyTopExceptions =
errorData.getDailyTopExceptions();
int chartNumber = 1;
for (String exception : dailyTopExceptions) {
String chartURLString =
exceptionToChartURLMap.get(exception);
URL chartURL = new URL(chartURLString);
ReadableByteChannel channel =
FileIOUtil.createReadableByteChannel(chartURL);
FileOutputStream output
=
FileIOUtil.createFileOutputStream(StoragePathUtil.getChartStoragePath(chartNumber));
downloadChartImageToFileSystem(channel, output);
chartNumber++;
}
}catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Performs the transfer of data from the Internet to the local
file system by creating channel, and writes byte by byte.
* @param channel created in
downloadHourlyChartsForExceptionsInList
* @param output created in
downloadHourlyChartsForExceptionsInList
* @throws IOException when there is an error transferring data.
*/
private void downloadChartImageToFileSystem
(ReadableByteChannel channel, FileOutputStream output)
throws IOException{
output.getChannel().transferFrom(channel, 0, 1 << 24);
channel.close();
output.close();
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-chart-api?hl=en.