com.google.api.ads.common.lib.utils
Class Media

java.lang.Object
  extended by com.google.api.ads.common.lib.utils.Media

public final class Media
extends Object

A utility class for retrieving media data.

Author:
Adam Rogal

Method Summary
static byte[] getMediaDataFromFile(File file)
          Gets the media data byte[] located in file.
static byte[] getMediaDataFromFile(String fileName)
          Gets the media data byte[] located in fileName.
static byte[] getMediaDataFromUrl(String url)
          Gets the media data byte[] located at url or null if the media could not be loaded.
static byte[] getMediaDataFromUrl(URL url)
          Gets the media data byte[] located at url or null if the media could not be loaded.
static void saveMediaDataToFile(byte[] mediaData, File file)
          Saves media data downloaded from an API in byte[] format into a file on the file system.
static void saveMediaDataToFile(byte[] mediaData, String fileName)
          Saves media data downloaded from an API in byte[] format into a file on the file system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMediaDataFromFile

public static byte[] getMediaDataFromFile(String fileName)
                                   throws IOException
Gets the media data byte[] located in fileName.

Parameters:
fileName - the media file to load
Returns:
the media data byte[] located in fileName
Throws:
IOException - if the media could not be read

getMediaDataFromFile

public static byte[] getMediaDataFromFile(File file)
                                   throws IOException
Gets the media data byte[] located in file.

Parameters:
file - the media file to load
Returns:
the media data byte[] located in file
Throws:
IOException - if the media could not be read

getMediaDataFromUrl

public static byte[] getMediaDataFromUrl(String url)
                                  throws IOException
Gets the media data byte[] located at url or null if the media could not be loaded.

Parameters:
url - the media URL to load
Returns:
the media data byte[] located at url
Throws:
IOException - if the media could not be read from the URL

getMediaDataFromUrl

public static byte[] getMediaDataFromUrl(URL url)
                                  throws IOException
Gets the media data byte[] located at url or null if the media could not be loaded.

Parameters:
url - the media URL to load
Returns:
the media data byte[] located at url
Throws:
IOException - if the media could not be read from the URL

saveMediaDataToFile

public static void saveMediaDataToFile(byte[] mediaData,
                                       String fileName)
                                throws FileNotFoundException,
                                       IOException
Saves media data downloaded from an API in byte[] format into a file on the file system.

Parameters:
mediaData - the media data byte[] to store on the file system
fileName - the name of the file on the file system to save the media data into
Throws:
FileNotFoundException - if the file exists but is a directory, does not exist but cannot be created, or cannot be opened for any reason
IOException - if the file cannot be written to

saveMediaDataToFile

public static void saveMediaDataToFile(byte[] mediaData,
                                       File file)
                                throws FileNotFoundException,
                                       IOException
Saves media data downloaded from an API in byte[] format into a file on the file system.

Parameters:
mediaData - the media data byte[] to store on the file system
file - the file on the file system to save the media data into
Throws:
FileNotFoundException - if the file exists but is a directory, does not exist but cannot be created, or cannot be opened for any reason
IOException - if the file cannot be written to


Copyright © 2012. All Rights Reserved.