Java Code Examples for java.io.FileOutputStream

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project amplafi-sworddance, under directory /src/main/java/com/sworddance/util/perf/.

Source file: LapTimerCollection.java

  38 
vote

/** 
 * Write out the stored LapTimers in Excel CVS format
 * @param fileName
 * @throws IOException
 */
public void writeCSV(String fileName) throws IOException {
  FileOutputStream f=new FileOutputStream(fileName);
  OutputStreamWriter f0=new OutputStreamWriter(f);
  try {
    this.writeCSV(f0);
  }
  finally {
    f0.close();
    f.close();
  }
}
 

Example 2

From project AceWiki, under directory /src/ch/uzh/ifi/attempto/acewiki/core/.

Source file: FileBasedStorage.java

  33 
vote

public void save(User user){
  try {
    String n=user.getUserBase().getOntology().getName();
    File d=new File(dir + "/" + n+ ".users");
    if (!d.exists())     d.mkdir();
    FileOutputStream out=new FileOutputStream(new File(dir + "/" + n+ ".users"+ "/"+ user.getId()));
    out.write(serialize(user).getBytes("UTF-8"));
    out.close();
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
}
 

Example 3

From project android-rackspacecloud, under directory /src/com/rackspacecloud/android/.

Source file: ContainerObjectDetails.java

  33 
vote

private boolean writeFile(byte[] data){
  String directoryName=Environment.getExternalStorageDirectory().getPath() + DOWNLOAD_DIRECTORY;
  File f=new File(directoryName);
  if (!f.isDirectory()) {
    if (!f.mkdir()) {
      return false;
    }
  }
  String filename=directoryName + "/" + objects.getCName();
  File object=new File(filename);
  BufferedOutputStream bos=null;
  try {
    FileOutputStream fos=new FileOutputStream(object);
    bos=new BufferedOutputStream(fos);
    bos.write(data);
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    if (bos != null) {
      try {
        bos.flush();
        bos.close();
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
    }
  }
  return true;
}
 

Example 4

From project Absolute-Android-RSS, under directory /src/com/AA/Services/.

Source file: RssService.java

  32 
vote

/** 
 * Writes the received data to the application settings so that data restoration is easier
 * @param articleList - List of all the articles that have been aggregated from the stream
 */
public static void writeData(Context context,List<Article> articleList){
  try {
    FileOutputStream fileStream=context.openFileOutput("articles",Context.MODE_PRIVATE);
    ObjectOutputStream writer=new ObjectOutputStream(fileStream);
    writer.writeObject(articleList);
    writer.close();
    fileStream.close();
  }
 catch (  IOException e) {
    Log.e("AARSS","Problem saving file.",e);
    return;
  }
}
 

Example 5

From project activejdbc, under directory /activejdbc-instrumentation/src/main/java/org/javalite/instrumentation/.

Source file: Instrumentation.java

  32 
vote

private static void generateModelsFile(List<CtClass> models,File target) throws IOException, ClassNotFoundException {
  String modelsFileName=target.getAbsolutePath() + System.getProperty("file.separator") + "activejdbc_models.properties";
  FileOutputStream fout=new FileOutputStream(modelsFileName);
  for (  CtClass model : models) {
    fout.write((model.getName() + ":" + getDatabaseName(model)+ "\n").getBytes());
  }
  fout.close();
}
 

Example 6

From project Activiti-KickStart, under directory /activiti-kickstart-java/src/test/java/org/activiti/kickstart/.

Source file: KickstartTest.java

  32 
vote

private void writeToFile(final String file,final byte[] data) throws IOException {
  File f=new File(file);
  FileOutputStream fout=new FileOutputStream(f);
  fout.write(data);
  fout.flush();
  fout.close();
}
 

Example 7

From project addis, under directory /application/src/main/java/org/drugis/addis/entities/.

Source file: DomainManager.java

  32 
vote

/** 
 * Save the domain to an XML file (new format, .addis)
 * @param file File to write the domain to.
 */
public void saveXMLDomain(File file) throws IOException {
  try {
    AddisData addisData=JAXBConvertor.convertDomainToAddisData(d_domain);
    FileOutputStream os=new FileOutputStream(file);
    saveAddisData(addisData,os);
  }
 catch (  ConversionException e) {
    throw new RuntimeException(e);
  }
}
 

Example 8

From project AeminiumRuntime, under directory /src/aeminium/runtime/utils/graphviz/.

Source file: DiGraphViz.java

  32 
vote

public boolean dump(File file){
  try {
    FileOutputStream fos=new FileOutputStream(file);
    dump(fos);
    fos.close();
    return true;
  }
 catch (  IOException e) {
  }
  return false;
}
 

Example 9

From project aether-core, under directory /aether-test-util/src/main/java/org/eclipse/aether/internal/test/impl/.

Source file: TestFileProcessor.java

  32 
vote

public void write(File file,String data) throws IOException {
  mkdirs(file.getParentFile());
  FileOutputStream fos=null;
  try {
    fos=new FileOutputStream(file);
    if (data != null) {
      fos.write(data.getBytes("UTF-8"));
    }
    fos.close();
  }
  finally {
    close(fos);
  }
}
 

Example 10

From project AlarmApp-Android, under directory /src/org/alarmapp/util/.

Source file: Device.java

  32 
vote

private static void writeInstallationFile(File installation) throws IOException {
  FileOutputStream out=new FileOutputStream(installation);
  String id=UUID.randomUUID().toString();
  out.write(id.getBytes());
  out.close();
}
 

Example 11

From project ALP, under directory /workspace/alp-reporter-fe/src/main/java/com/lohika/alp/reporter/fe/logs/.

Source file: LogStorageFS.java

  32 
vote

@Override public void saveLog(long testMethodId,String fileName,InputStream is,String filePath) throws IOException {
  File testMethodDir=new File(filePath + "/" + testMethodId);
  if (!testMethodDir.exists())   testMethodDir.mkdirs();
  File logfile=new File(testMethodDir,fileName);
  FileOutputStream os=new FileOutputStream(logfile);
  int c;
  while ((c=is.read()) != -1)   os.write(c);
  os.flush();
  os.close();
}
 

Example 12

From project AmDroid, under directory /httpclientandroidlib/src/ch/boye/httpclientandroidlib/impl/client/cache/.

Source file: FileResourceFactory.java

  32 
vote

public Resource copy(final String requestId,final Resource resource) throws IOException {
  File file=generateUniqueCacheFile(requestId);
  if (resource instanceof FileResource) {
    File src=((FileResource)resource).getFile();
    IOUtils.copyFile(src,file);
  }
 else {
    FileOutputStream out=new FileOutputStream(file);
    IOUtils.copyAndClose(resource.getInputStream(),out);
  }
  return new FileResource(file);
}
 

Example 13

From project andlytics, under directory /src/com/github/andlyticsproject/gwt/.

Source file: GwtParser.java

  32 
vote

private static void dumpToFile(Object obj,String name) throws Exception {
  FileOutputStream fos=new FileOutputStream("/sdcard/" + name + dumpNumber+ ".json");
  fos.write(obj.toString().getBytes("UTF-8"));
  fos.flush();
  fos.close();
}
 

Example 14

From project android-aac-enc, under directory /src/com/todoroo/aacenc/.

Source file: AACToM4A.java

  32 
vote

public void convert(Context context,String infile,String outfile) throws IOException {
  AACToM4A.context=context;
  InputStream input=new FileInputStream(infile);
  PushbackInputStream pbi=new PushbackInputStream(input,100);
  System.err.println("well you got " + input.available());
  Movie movie=new Movie();
  Track audioTrack=new AACTrackImpl(pbi);
  movie.addTrack(audioTrack);
  IsoFile out=new DefaultMp4Builder().build(movie);
  FileOutputStream output=new FileOutputStream(outfile);
  out.getBox(output.getChannel());
  output.close();
}
 

Example 15

From project android-client, under directory /xwiki-android-test-fixture-setup/src/org/xwiki/test/integration/utils/.

Source file: XWikiExecutor.java

  32 
vote

private void saveProperties(String path,Properties properties) throws Exception {
  FileOutputStream fos=new FileOutputStream(path);
  try {
    properties.store(fos,null);
  }
  finally {
    fos.close();
  }
}
 

Example 16

From project android-joedayz, under directory /Proyectos/Archivos/src/net/ivanvega/Archivos/.

Source file: MainActivity.java

  32 
vote

@Override public void onClick(View arg0){
  if (arg0.equals(btnGuardar)) {
    String str=txtTexto.getText().toString();
    FileOutputStream fout=null;
    try {
      fout=openFileOutput("archivoTexto.txt",MODE_WORLD_READABLE);
      OutputStreamWriter ows=new OutputStreamWriter(fout);
      ows.write(str);
      ows.flush();
      ows.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    Toast.makeText(getBaseContext(),"El archivo se ha almacenado!!!",Toast.LENGTH_SHORT).show();
    txtTexto.setText("");
  }
  if (arg0.equals(btnAbrir)) {
    try {
      FileInputStream fin=openFileInput("archivoTexto.txt");
      InputStreamReader isr=new InputStreamReader(fin);
      char[] inputBuffer=new char[READ_BLOCK_SIZE];
      String str="";
      int charRead;
      while ((charRead=isr.read(inputBuffer)) > 0) {
        String strRead=String.copyValueOf(inputBuffer,0,charRead);
        str+=strRead;
        inputBuffer=new char[READ_BLOCK_SIZE];
      }
      txtTexto.setText(str);
      isr.close();
      Toast.makeText(getBaseContext(),"El archivo ha sido cargado",Toast.LENGTH_SHORT).show();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}
 

Example 17

From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.

Source file: MapView.java

  32 
vote

/** 
 * Makes a screenshot of the currently visible map and saves it as compressed image. Zoom buttons, scale bar, overlays, menus and the title bar are not included in the screenshot.
 * @param fileName the name of the image file. If the file exists, it will be overwritten.
 * @param format the file format of the compressed image.
 * @param quality value from 0 (low) to 100 (high). Has no effect on some formats like PNG.
 * @return true if the image was saved successfully, false otherwise.
 * @throws IOException if an error occurs while writing the file.
 */
public boolean makeScreenshot(CompressFormat format,int quality,String fileName) throws IOException {
  FileOutputStream outputStream=new FileOutputStream(fileName);
  boolean success;
synchronized (this.matrix) {
    success=this.mapViewBitmap1.compress(format,quality,outputStream);
  }
  outputStream.close();
  return success;
}
 

Example 18

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: OcrInitAsyncTask.java

  32 
vote

/** 
 * Unzip the given Zip file, located in application assets, into the given destination file.
 * @param sourceFilename Name of the file in assets
 * @param destinationDir Directory to save the destination file in
 * @param destinationFile File to unzip into, excluding path
 * @return
 * @throws IOException
 * @throws FileNotFoundException
 */
private boolean installZipFromAssets(String sourceFilename,File destinationDir,File destinationFile) throws IOException, FileNotFoundException {
  publishProgress("Uncompressing data for " + languageName + "...","0");
  ZipInputStream inputStream=new ZipInputStream(context.getAssets().open(sourceFilename));
  for (ZipEntry entry=inputStream.getNextEntry(); entry != null; entry=inputStream.getNextEntry()) {
    destinationFile=new File(destinationDir,entry.getName());
    if (entry.isDirectory()) {
      destinationFile.mkdirs();
    }
 else {
      long zippedFileSize=entry.getSize();
      FileOutputStream outputStream=new FileOutputStream(destinationFile);
      final int BUFFER=8192;
      BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(outputStream,BUFFER);
      int unzippedSize=0;
      int count=0;
      Integer percentComplete=0;
      Integer percentCompleteLast=0;
      byte[] data=new byte[BUFFER];
      while ((count=inputStream.read(data,0,BUFFER)) != -1) {
        bufferedOutputStream.write(data,0,count);
        unzippedSize+=count;
        percentComplete=(int)((unzippedSize / (long)zippedFileSize) * 100);
        if (percentComplete > percentCompleteLast) {
          publishProgress("Uncompressing data for " + languageName + "...",percentComplete.toString(),"0");
          percentCompleteLast=percentComplete;
        }
      }
      bufferedOutputStream.close();
    }
    inputStream.closeEntry();
  }
  inputStream.close();
  return true;
}
 

Example 19

From project android-rindirect, under directory /rindirect/src/test/java/de/akquinet/android/rindirect/.

Source file: RindirectTest.java

  32 
vote

@BeforeClass public static void configure() throws FileNotFoundException, IOException {
  File template=new File("src/main/resources/templates/R.vm");
  File out=new File("target/test-classes/templates");
  out.mkdirs();
  out=new File("target/test-classes/templates/R.vm");
  copyInputStream(new FileInputStream(template),new FileOutputStream(out));
}
 

Example 20

From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.

Source file: MobeelizerFileService.java

  32 
vote

private String savaFile(final String guid,final InputStream stream){
  File dir=getStorageDirectory();
  File file=new File(dir,guid);
  FileOutputStream fos=null;
  try {
    file.createNewFile();
    fos=new FileOutputStream(file);
    byte[] buffer=new byte[4096];
    int read;
    while ((read=stream.read(buffer)) != -1) {
      fos.write(buffer,0,read);
    }
    fos.flush();
  }
 catch (  FileNotFoundException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
catch (  IOException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
 finally {
    if (fos != null) {
      try {
        fos.close();
      }
 catch (      IOException e) {
        Log.w(TAG,e.getMessage(),e);
      }
    }
  }
  return file.getAbsolutePath();
}
 

Example 21

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: LinphoneManager.java

  32 
vote

private void copyFromPackage(Context context,int ressourceId,String target) throws IOException {
  FileOutputStream lOutputStream=context.openFileOutput(target,0);
  InputStream lInputStream=mR.openRawResource(ressourceId);
  int readByte;
  byte[] buff=new byte[8048];
  while ((readByte=lInputStream.read(buff)) != -1) {
    lOutputStream.write(buff,0,readByte);
  }
  lOutputStream.flush();
  lOutputStream.close();
  lInputStream.close();
}
 

Example 22

From project AndroidBillingLibrary, under directory /AndroidBillingLibrary/src/net/robotmedia/billing/utils/.

Source file: Installation.java

  32 
vote

private static void writeInstallationFile(File installation) throws IOException {
  FileOutputStream out=new FileOutputStream(installation);
  String id=UUID.randomUUID().toString();
  out.write(id.getBytes());
  out.close();
}
 

Example 23

From project android_5, under directory /src/aarddict/android/.

Source file: DictionariesActivity.java

  32 
vote

void saveVerifyData() throws IOException {
  File verifyDir=getDir("verify",0);
  File verifyFile=new File(verifyDir,"verifydata");
  FileOutputStream fout=new FileOutputStream(verifyFile);
  ObjectOutputStream oout=new ObjectOutputStream(fout);
  oout.writeObject(verifyData);
}
 

Example 24

From project android_external_guava, under directory /src/com/google/common/io/.

Source file: FileBackedOutputStream.java

  32 
vote

/** 
 * Checks if writing  {@code len} bytes would go over threshold, andswitches to file buffering if so.
 */
private void update(int len) throws IOException {
  if (file == null && (memory.getCount() + len > fileThreshold)) {
    File temp=File.createTempFile("FileBackedOutputStream",null);
    if (resetOnFinalize) {
      temp.deleteOnExit();
    }
    FileOutputStream transfer=new FileOutputStream(temp);
    transfer.write(memory.getBuffer(),0,memory.getCount());
    transfer.flush();
    out=transfer;
    file=temp;
    memory=null;
  }
}
 

Example 25

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/adapter/.

Source file: Parser.java

  32 
vote

/** 
 * Turns off data capture; writes the captured data to a specified file.
 */
public void captureOff(Context context,String file){
  try {
    FileOutputStream out=context.openFileOutput(file,Context.MODE_WORLD_WRITEABLE);
    out.write(captureArray.toString().getBytes());
    out.close();
  }
 catch (  FileNotFoundException e) {
  }
catch (  IOException e) {
  }
}
 

Example 26

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: Camera.java

  32 
vote

public boolean saveDataToFile(String filePath,byte[] data){
  FileOutputStream f=null;
  try {
    f=new FileOutputStream(filePath);
    f.write(data);
  }
 catch (  IOException e) {
    return false;
  }
 finally {
    MenuHelper.closeSilently(f);
  }
  return true;
}
 

Example 27

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/data/.

Source file: DownloadUtils.java

  32 
vote

public static boolean requestDownload(JobContext jc,URL url,File file){
  FileOutputStream fos=null;
  try {
    fos=new FileOutputStream(file);
    return download(jc,url,fos);
  }
 catch (  Throwable t) {
    return false;
  }
 finally {
    Utils.closeSilently(fos);
  }
}
 

Example 28

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.

Source file: Util.java

  32 
vote

public static final void copyFromAssets(Context context,String source,String destination) throws IOException {
  InputStream is=context.getAssets().open(source);
  int size=is.available();
  byte[] buffer=new byte[size];
  is.read(buffer);
  is.close();
  FileOutputStream output=context.openFileOutput(destination,Context.MODE_PRIVATE);
  output.write(buffer);
  output.close();
  Log.d(TAG,source + " asset copied to " + destination);
}
 

Example 29

From project android_packages_apps_Tag, under directory /src/com/android/apps/tag/provider/.

Source file: TagProvider.java

  32 
vote

@Override public void writeMimeDataToPipe(ParcelFileDescriptor output,Uri uri){
  NdefRecord record=getRecord(uri);
  if (record == null)   return;
  try {
    byte[] data=record.getPayload();
    FileOutputStream os=new FileOutputStream(output.getFileDescriptor());
    os.write(data);
    os.flush();
  }
 catch (  IOException e) {
    Log.e(TAG,"failed to write MIME data to " + uri,e);
  }
}
 

Example 30

From project androvoip, under directory /src/com/mexuar/corraleta/audio/javasound/.

Source file: AEC.java

  32 
vote

/** 
 * writeSample
 * @param buff byte[]
 */
public void writeSample(byte[] buff,byte[] buff2,int sno){
  String fname="" + sno + ".raw";
  try {
    FileOutputStream s=new FileOutputStream(fname);
    s.write(buff);
    s.write(buff2);
    s.close();
  }
 catch (  IOException ex) {
    Log.warn(ex.getMessage());
  }
}
 

Example 31

From project anode, under directory /bridge-stub-generator/src/org/meshpoint/anode/stub/.

Source file: StubGenerator.java

  32 
vote

/** 
 * Create a ClassWriter instance for the specified stub class
 * @param className class name, without package component
 * @param mode stub mode
 * @throws IOException
 */
public ClassWriter(String className,int mode) throws IOException {
  String stubPackage=StubUtil.getStubPackage(mode).replace('.','/');
  File packageDir=new File(destination.toString() + '/' + stubPackage);
  packageDir.mkdirs();
  if (!packageDir.exists())   throw new IOException("Unable to create package directory (" + packageDir.toString() + ")");
  String classFilename=className + ".java";
  File classFile=new File(packageDir,classFilename);
  FileOutputStream fos=new FileOutputStream(classFile);
  this.ps=new PrintStream(fos);
}
 

Example 32

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generic/.

Source file: FileUtils.java

  31 
vote

static void writejarEntry(JarInputStream jarfile,ZipEntry entry,String path,boolean verbose) throws IOException {
  File tofp=new File(path + File.separator + entry.getName());
  tofp.mkdirs();
  if (entry.isDirectory()) {
    return;
  }
 else {
    tofp.delete();
  }
  int buffer=(int)(entry.getSize() > 0 ? entry.getSize() : 1024);
  int count=0;
  int sumcount=0;
  byte data[]=new byte[buffer];
  FileOutputStream fos=null;
  try {
    fos=new FileOutputStream(tofp);
  }
 catch (  Exception e) {
    System.err.println("Unable to extract file:" + tofp + " from "+ path);
    return;
  }
  BufferedOutputStream dest=new BufferedOutputStream(fos,buffer);
  while ((count=jarfile.read(data,0,buffer)) != -1) {
    dest.write(data,0,count);
    sumcount+=count;
  }
  if (verbose)   System.out.println("Uncompressed: " + entry.getName() + " size: "+ sumcount+ " with buffersize: "+ buffer);
  dest.flush();
  dest.close();
}
 

Example 33

From project abalone-android, under directory /src/com/bytopia/abalone/.

Source file: GameActivity.java

  31 
vote

@Override protected void onPause(){
  Log.d("state","paused");
  try {
    FileOutputStream fos=openFileOutput(FILE_NAME,Context.MODE_PRIVATE);
    ObjectOutputStream oos=new ObjectOutputStream(fos);
    oos.writeObject(game.getBoard());
    oos.writeByte(game.getSide());
    oos.writeByte(game.getVsType());
    if (cpuType != null) {
      oos.writeObject(cpuType);
    }
    oos.writeByte((byte)game.getBoard().getMarblesCaptured(Side.BLACK));
    oos.writeByte((byte)game.getBoard().getMarblesCaptured(Side.WHITE));
    oos.close();
  }
 catch (  FileNotFoundException e) {
    Log.d("state","FileNotFound");
  }
catch (  IOException e) {
    Log.d("state","IO Exception");
  }
  super.onPause();
}
 

Example 34

From project ActionBarSherlock, under directory /samples/demos/src/com/actionbarsherlock/sample/demos/.

Source file: ShareActionProviders.java

  31 
vote

/** 
 * Copies a private raw resource content to a publicly readable file such that the latter can be shared with other applications.
 */
private void copyPrivateRawResuorceToPubliclyAccessibleFile(){
  InputStream inputStream=null;
  FileOutputStream outputStream=null;
  try {
    inputStream=getResources().openRawResource(R.raw.robot);
    outputStream=openFileOutput(SHARED_FILE_NAME,Context.MODE_WORLD_READABLE | Context.MODE_APPEND);
    byte[] buffer=new byte[1024];
    int length=0;
    try {
      while ((length=inputStream.read(buffer)) > 0) {
        outputStream.write(buffer,0,length);
      }
    }
 catch (    IOException ioe) {
    }
  }
 catch (  FileNotFoundException fnfe) {
  }
 finally {
    try {
      inputStream.close();
    }
 catch (    IOException ioe) {
    }
    try {
      outputStream.close();
    }
 catch (    IOException ioe) {
    }
  }
}
 

Example 35

From project AdminCmd, under directory /src/main/java/be/Balor/Tools/Files/Unicode/.

Source file: UnicodeUtil.java

  31 
vote

/** 
 * Save a String to a file in UTF8 with Signature
 * @param file file to save
 * @param data data to write
 * @param append append data
 * @throws IOException something goes wrong with the file
 */
public static void saveUTF8File(final File file,final String data,final boolean append) throws IOException {
  BufferedWriter bw=null;
  OutputStreamWriter osw=null;
  final FileOutputStream fos=new FileOutputStream(file,append);
  try {
    if (file.length() < 1) {
      fos.write(UTF8_BOMS);
    }
    osw=new OutputStreamWriter(fos,"UTF-8");
    bw=new BufferedWriter(osw);
    if (data != null) {
      bw.write(data);
    }
  }
  finally {
    try {
      bw.close();
      fos.close();
    }
 catch (    final Exception ex) {
    }
  }
}
 

Example 36

From project adt-maven-plugin, under directory /src/main/java/com/yelbota/plugins/adt/model/.

Source file: ApplicationDescriptorModel.java

  31 
vote

/** 
 * Pretty print to outputFile
 * @param outputFile file to print.
 * @throws MojoFailureException
 */
public void printToFile(File outputFile) throws MojoFailureException {
  configureDescriptor();
  OutputFormat format=new OutputFormat(dom);
  format.setLineWidth(65);
  format.setIndenting(true);
  format.setIndent(2);
  try {
    FileOutputStream out=new FileOutputStream(outputFile);
    XMLSerializer serializer=new XMLSerializer(out,format);
    serializer.serialize(dom);
  }
 catch (  IOException e) {
    throw new MojoFailureException("Cant write to " + outputFile.getPath());
  }
}
 

Example 37

From project Agot-Java, under directory /src/main/java/got/utility/.

Source file: ConnectionCreate.java

  31 
vote

/** 
 * saveCenters() Saves the centers to disk.
 */
private void saveCenters(){
  try {
    final String fileName=new FileSave("Where To Save centers.txt ?","connection.xml").getPathString();
    if (fileName == null) {
      return;
    }
    final FileOutputStream out=new FileOutputStream(fileName);
    DocumentBuilderFactory docFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder=docFactory.newDocumentBuilder();
    Document doc=docBuilder.newDocument();
    Element rootElement=doc.createElement("Connections");
    doc.appendChild(rootElement);
    for (    Connection conn : m_conns) {
      Element connection=doc.createElement("Connection");
      rootElement.appendChild(connection);
      Attr attr=doc.createAttribute("t1");
      attr.setValue(conn.start);
      connection.setAttributeNode(attr);
      Attr attr1=doc.createAttribute("t2");
      attr1.setValue(conn.end);
      connection.setAttributeNode(attr1);
    }
    TransformerFactory transformerFactory=TransformerFactory.newInstance();
    Transformer transformer=transformerFactory.newTransformer();
    DOMSource source=new DOMSource(doc);
    StreamResult result=new StreamResult(new File(fileName));
    transformer.transform(source,result);
    System.out.println("Data written to :" + new File(fileName).getCanonicalPath());
  }
 catch (  final FileNotFoundException ex) {
    ex.printStackTrace();
  }
catch (  final HeadlessException ex) {
    ex.printStackTrace();
  }
catch (  final Exception ex) {
    ex.printStackTrace();
  }
}
 

Example 38

From project akubra, under directory /akubra-fs/src/main/java/org/akubraproject/fs/.

Source file: FSBlob.java

  31 
vote

@Override public OutputStream openOutputStream(long estimatedSize,boolean overwrite) throws IOException {
  ensureOpen();
  if (!overwrite && file.exists())   throw new DuplicateBlobException(getId());
  makeParentDirs(file);
  if (modified != null)   modified.add(file);
  return manager.manageOutputStream(getConnection(),new FileOutputStream(file));
}
 

Example 39

From project and-bible, under directory /jsword-tweaks/src/util/java/net/andbible/util/.

Source file: MJDIndexAll.java

  31 
vote

private void addPropertiesFile(){
  Properties indexProperties=new Properties();
  indexProperties.put("version","1");
  indexProperties.put("java.specification.version",System.getProperty("java.specification.version"));
  indexProperties.put("java.vendor",System.getProperty("java.vendor"));
  indexProperties.put("lucene.specification.version",LucenePackage.get().getSpecificationVersion());
  List<Book> books=(List<Book>)BookInstaller.getInstalledBooks();
  for (  Book book : books) {
    System.out.println("Adding properties file:" + book.getInitials() + " name:"+ book.getName());
    String initials=book.getInitials();
    File indexPropertiesFile=new File(LUCENE_INDEX_DIR_FILE,initials + "/index.properties");
    FileOutputStream fos=null;
    try {
      fos=new FileOutputStream(indexPropertiesFile);
      indexProperties.store(fos,null);
    }
 catch (    IOException ioe) {
      System.out.println(ioe.getMessage());
      ioe.printStackTrace();
    }
 finally {
      if (fos != null) {
        try {
          fos.close();
        }
 catch (        IOException e2) {
          e2.printStackTrace();
        }
      }
    }
  }
}
 

Example 40

From project Android, under directory /app/src/main/java/com/github/mobile/util/.

Source file: AvatarLoader.java

  31 
vote

/** 
 * Fetch avatar from URL
 * @param url
 * @param userId
 * @return bitmap
 */
protected BitmapDrawable fetchAvatar(final String url,final String userId){
  File rawAvatar=new File(avatarDir,userId + "-raw");
  HttpRequest request=HttpRequest.get(url);
  if (request.ok())   request.receive(rawAvatar);
  if (!rawAvatar.exists() || rawAvatar.length() == 0)   return null;
  Bitmap bitmap=decode(rawAvatar);
  if (bitmap == null) {
    rawAvatar.delete();
    return null;
  }
  bitmap=ImageUtils.roundCorners(bitmap,cornerRadius);
  if (bitmap == null) {
    rawAvatar.delete();
    return null;
  }
  File roundedAvatar=new File(avatarDir,userId);
  FileOutputStream output=null;
  try {
    output=new FileOutputStream(roundedAvatar);
    if (bitmap.compress(PNG,100,output))     return new BitmapDrawable(context.getResources(),bitmap);
 else     return null;
  }
 catch (  IOException e) {
    Log.d(TAG,"Exception writing rounded avatar",e);
    return null;
  }
 finally {
    if (output != null)     try {
      output.close();
    }
 catch (    IOException e) {
    }
    rawAvatar.delete();
  }
}
 

Example 41

From project android-bankdroid, under directory /src/com/liato/bankdroid/liveview/.

Source file: PluginUtils.java

  31 
vote

/** 
 * Stores icon to phone file system
 * @param resources Reference to project resources
 * @param resource Reference to specific resource
 * @param fileName The icon file name
 */
public static String storeIconToFile(Context ctx,Resources resources,int resource,String fileName){
  Log.d(PluginConstants.LOG_TAG,"Store icon to file.");
  if (resources == null) {
    return "";
  }
  Bitmap bitmap=BitmapFactory.decodeStream(resources.openRawResource(resource));
  try {
    FileOutputStream fos=ctx.openFileOutput(fileName,Context.MODE_WORLD_READABLE);
    bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);
    fos.flush();
    fos.close();
  }
 catch (  IOException e) {
    Log.e(PluginConstants.LOG_TAG,"Failed to store to device",e);
  }
  File iconFile=ctx.getFileStreamPath(fileName);
  Log.d(PluginConstants.LOG_TAG,"Icon stored. " + iconFile.getAbsolutePath());
  return iconFile.getAbsolutePath();
}
 

Example 42

From project Android-FFXIEQ, under directory /ffxieq/src/com/github/kanata3249/ffxieq/android/db/.

Source file: FFXIDatabase.java

  31 
vote

void copyDatabaseFromSD(String sd_path) throws IOException {
  File outDir=new File(DB_PATH);
  outDir.mkdir();
  FileChannel channelSource=new FileInputStream(sd_path + DB_NAME).getChannel();
  FileChannel channelTarget=new FileOutputStream(DB_PATH + DB_NAME).getChannel();
  channelSource.transferTo(0,channelSource.size(),channelTarget);
  channelSource.close();
  channelTarget.close();
  File from=new File(sd_path + DB_NAME);
  File to=new File(DB_PATH + DB_NAME);
  to.setLastModified(from.lastModified());
}
 

Example 43

From project Android-Flashcards, under directory /src/com/secretsockssoftware/androidflashcards/.

Source file: AndroidFlashcards.java

  31 
vote

private LessonListItem parseLesson(File f,File bf,String fbase){
  Lesson l=null;
  LessonListItem lli=null;
  handler.sendMessage(handler.obtainMessage(2,"Parsing: " + fbase));
  if (f.length() <= 0) {
    if (f.delete())     handler.sendMessage(handler.obtainMessage(3,f.getName()));
    return null;
  }
  try {
    FileOutputStream fos=new FileOutputStream(bf);
    ObjectOutputStream oos=new ObjectOutputStream(fos);
    if (f.getName().endsWith(".xml"))     l=parseXML(f,fbase);
 else     if (f.getName().endsWith(".csv"))     l=parseCSV(f,fbase);
    if (l != null) {
      oos.writeObject(l);
      oos.close();
      lli=new LessonListItem(bf.getAbsolutePath(),f.getAbsolutePath(),l.name(),l.description(),"Cards: " + l.cardCount(),false);
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return lli;
}
 

Example 44

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/helpers/.

Source file: ImageHelper.java

  31 
vote

public static String createGifThumbnail(String originalPath){
  try {
    String thumbPath=generateGifThumbPath(originalPath);
    Bitmap originalBitmap=getDesirableBitmap(originalPath,THUMBNAILSIZE);
    int oWidth=originalBitmap.getWidth();
    int oHeight=originalBitmap.getHeight();
    int thumbSize=THUMBNAILSIZE;
    if (oWidth < thumbSize)     thumbSize=oWidth;
    if (oHeight < thumbSize)     thumbSize=oHeight;
    int thumbWidth=thumbSize;
    int thumbHeight=thumbSize;
    if (oWidth < oHeight) {
      thumbHeight=(int)(oHeight * (double)thumbWidth / oWidth);
    }
 else {
      thumbWidth=(int)(oWidth * (double)thumbHeight / oHeight);
    }
    Bitmap thumbBitmap=Bitmap.createScaledBitmap(originalBitmap,thumbWidth,thumbHeight,false);
    originalBitmap.recycle();
    FileOutputStream fos=new FileOutputStream(thumbPath);
    thumbBitmap.compress(Bitmap.CompressFormat.JPEG,100,fos);
    fos.flush();
    fos.close();
    return thumbPath;
  }
 catch (  Exception ex) {
    ex.printStackTrace();
  }
  return null;
}
 

Example 45

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/preference/activity/.

Source file: PreferencesCreateBackupActivity.java

  31 
vote

public Void doInBackground(String... filename){
  try {
    String message=getString(R.string.status_checking_media);
    Log.d(cTag,message);
    publishProgress(Progress.createProgress(0,message));
    String storage_state=Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(storage_state)) {
      message=getString(R.string.warning_media_not_mounted,storage_state);
      reportError(message);
    }
 else {
      File dir=Environment.getExternalStorageDirectory();
      final File backupFile=new File(dir,filename[0]);
      message=getString(R.string.status_creating_backup);
      Log.d(cTag,message);
      publishProgress(Progress.createProgress(5,message));
      if (backupFile.exists()) {
        publishProgress(Progress.createErrorProgress("",new Runnable(){
          @Override public void run(){
            showFileExistsWarning(backupFile);
          }
        }
));
      }
 else {
        backupFile.createNewFile();
        FileOutputStream out=new FileOutputStream(backupFile);
        writeBackup(out);
      }
    }
  }
 catch (  Exception e) {
    String message=getString(R.string.warning_backup_failed,e.getMessage());
    reportError(message);
  }
  return null;
}
 

Example 46

From project Android-SQL-Helper, under directory /src/com/sgxmobileapps/androidsqlhelper/processor/model/.

Source file: Schema.java

  31 
vote

public void storeSchemaProperties(File outDir) throws IOException {
  Properties props=new Properties();
  props.setProperty(KEY_PACKAGE,mPackage);
  props.setProperty(KEY_ADAPTER_CLASS_NAME,mDbAdapterClassName);
  props.setProperty(KEY_METADATA_CLASS_NAME,mMetadataClassName);
  props.setProperty(KEY_DB_NAME,mDbName);
  props.setProperty(KEY_DB_VERSION,mDbVersion);
  props.setProperty(KEY_AUTHOR,mAuthor);
  props.setProperty(KEY_LICENSE,mLicense);
  props.setProperty(KEY_LICENSE_FILE,mLicenseFile);
  props.store(new FileOutputStream(new File(outDir,SCHEMA_PROPERTIES_FILE)),null);
}
 

Example 47

From project Android-Terminal-Emulator, under directory /examples/pathbroadcasts/src/jackpal/androidterm/sample/pathbroadcasts/.

Source file: PathReceiver.java

  31 
vote

private File setupBinDir(Context context){
  String dataDir=getDataDir(context);
  File binDir=new File(dataDir,"bin");
  if (!binDir.exists()) {
    try {
      binDir.mkdir();
      chmod("755",binDir.getAbsolutePath());
    }
 catch (    Exception e) {
    }
  }
  File hello=new File(binDir,"hello");
  if (!hello.exists()) {
    try {
      InputStream src=context.getAssets().open("hello");
      FileOutputStream dst=new FileOutputStream(hello);
      copyStream(dst,src);
      chmod("755",hello.getAbsolutePath());
    }
 catch (    Exception e) {
    }
  }
  return binDir;
}
 

Example 48

From project android-tether, under directory /src/og/android/tether/system/.

Source file: CoreTask.java

  31 
vote

public void save() throws Exception {
  FileOutputStream fos=null;
  File file=new File(DATA_FILE_PATH + "/conf/whitelist_mac.conf");
  try {
    fos=new FileOutputStream(file);
    for (    String mac : this.whitelist) {
      fos.write((mac + "\n").getBytes());
    }
  }
  finally {
    if (fos != null) {
      try {
        fos.close();
      }
 catch (      IOException e) {
      }
    }
  }
}
 

Example 49

From project AndroidCommon, under directory /src/com/asksven/android/common/utils/.

Source file: DataStorage.java

  31 
vote

public static boolean objectToFile(Context context,String fileName,Object serializableObject){
  boolean bRet=true;
  if (!(serializableObject instanceof java.io.Serializable)) {
    Log.e(TAG,"The object is not serializable: " + fileName);
    return false;
  }
  try {
    FileOutputStream fos=context.openFileOutput(fileName,Context.MODE_PRIVATE);
    ObjectOutputStream os=new ObjectOutputStream(fos);
    os.writeObject(serializableObject);
    os.close();
  }
 catch (  Exception e) {
    Log.e(TAG,"An error occured while writing " + fileName + " "+ e.getMessage());
    bRet=false;
  }
  return bRet;
}
 

Example 50

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/util/.

Source file: ImportUtilities.java

  31 
vote

public static boolean addBookCoverToCache(BooksStore.Book book,Bitmap bitmap){
  File cacheDirectory;
  try {
    cacheDirectory=ensureCache();
  }
 catch (  IOException e) {
    return false;
  }
  File coverFile=new File(cacheDirectory,book.getInternalId());
  FileOutputStream out=null;
  try {
    out=new FileOutputStream(coverFile);
    bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
  }
 catch (  FileNotFoundException e) {
    return false;
  }
 finally {
    IOUtilities.closeStream(out);
  }
  return true;
}
 

Example 51

From project androidquery, under directory /src/com/androidquery/util/.

Source file: AQUtility.java

  31 
vote

public static void write(File file,byte[] data){
  try {
    if (!file.exists()) {
      try {
        file.createNewFile();
      }
 catch (      Exception e) {
        AQUtility.debug("file create fail",file);
        AQUtility.report(e);
      }
    }
    FileOutputStream fos=new FileOutputStream(file);
    fos.write(data);
    fos.close();
  }
 catch (  Exception e) {
    AQUtility.report(e);
  }
}
 

Example 52

From project androidTileMapEditor_1, under directory /src/it/sineo/android/tileMapEditor/.

Source file: TiledMapActivity.java

  31 
vote

@Override protected File doInBackground(String... params){
  try {
    File destDirectory=Util.getExternalStorageDirectory();
    File destFile=new File(destDirectory,filename);
    byte[] pngData=view.export(Bitmap.CompressFormat.PNG,90);
    FileOutputStream fos=new FileOutputStream(destFile);
    fos.write(pngData);
    fos.flush();
    fos.close();
    Log.d(TAG,"image size in bytes: " + destFile.length());
    return destFile;
  }
 catch (  IOException ioex) {
    ioex.printStackTrace();
    Toast.makeText(TiledMapActivity.this,String.format(getString(R.string.tiledMap_export_ioerror),ioex.getMessage()),Toast.LENGTH_LONG).show();
    return null;
  }
catch (  OutOfMemoryError oome) {
    oome.printStackTrace();
    Toast.makeText(TiledMapActivity.this,R.string.tiledMap_export_oom,Toast.LENGTH_LONG).show();
    return null;
  }
}
 

Example 53

From project androidZenWriter, under directory /src/com/javaposse/android/zenwriter/.

Source file: AndroidZenWriterActivity.java

  31 
vote

protected void saveFile(String filename){
  FileOutputStream fos=null;
  EditText editText=(EditText)findViewById(R.id.editText1);
  if (editText != null) {
    String content=editText.getText().toString();
    if (currentNote.getName().length() == 0) {
      currentNote.setName(Note.getDefaultNameFromContent(content,defaultNameLength));
    }
    try {
      fos=openFileOutput(filename,MODE_PRIVATE);
      fos.write(content.getBytes());
    }
 catch (    IOException e) {
      Log.e("SaveFile","Failed to save file: ",e);
    }
 finally {
      if (fos != null) {
        try {
          fos.close();
        }
 catch (        IOException e) {
        }
      }
    }
    Toast.makeText(this,"Saved file",Toast.LENGTH_SHORT).show();
  }
}
 

Example 54

From project android_device_samsung_galaxys2, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: Utils.java

  31 
vote

/** 
 * Write a string value to the specified file.
 * @param filename      The filename
 * @param value         The value
 */
public static void writeValue(String filename,String value){
  try {
    FileOutputStream fos=new FileOutputStream(new File(filename));
    fos.write(value.getBytes());
    fos.flush();
    fos.getFD().sync();
    fos.close();
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 55

From project android_device_samsung_galaxys2_1, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: Utils.java

  31 
vote

/** 
 * Write a string value to the specified file.
 * @param filename      The filename
 * @param value         The value
 */
public static void writeValue(String filename,String value){
  try {
    FileOutputStream fos=new FileOutputStream(new File(filename));
    fos.write(value.getBytes());
    fos.flush();
    fos.getFD().sync();
    fos.close();
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 56

From project android_device_samsung_i777, under directory /DeviceSettings/src/com/cyanogenmod/settings/device/.

Source file: Utils.java

  31 
vote

/** 
 * Write a string value to the specified file.
 * @param filename      The filename
 * @param value         The value
 */
public static void writeValue(String filename,String value){
  try {
    FileOutputStream fos=new FileOutputStream(new File(filename));
    fos.write(value.getBytes());
    fos.flush();
    fos.getFD().sync();
    fos.close();
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 57

From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/.

Source file: FileManagerActivity.java

  31 
vote

private boolean copy(File oldFile,File newFile){
  try {
    FileInputStream input=new FileInputStream(oldFile);
    FileOutputStream output=new FileOutputStream(newFile);
    byte[] buffer=new byte[COPY_BUFFER_SIZE];
    while (true) {
      int bytes=input.read(buffer);
      if (bytes <= 0) {
        break;
      }
      output.write(buffer,0,bytes);
    }
    output.close();
    input.close();
  }
 catch (  Exception e) {
    return false;
  }
  return true;
}
 

Example 58

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: DiskCache.java

  31 
vote

private void writeIndex(){
  File tempFile=null;
  final String tempFilePath=mCacheDirectoryPath;
  final String indexFilePath=getIndexFilePath();
  try {
    tempFile=File.createTempFile("DiskCache",null,new File(tempFilePath));
  }
 catch (  Exception e) {
    Log.e(TAG,"Unable to create or tempFile " + tempFilePath);
    return;
  }
  try {
    final FileOutputStream fileOutput=new FileOutputStream(tempFile);
    final BufferedOutputStream bufferedOutput=new BufferedOutputStream(fileOutput,1024);
    final DataOutputStream dataOutput=new DataOutputStream(bufferedOutput);
    final int numRecords=mIndexMap.size();
    dataOutput.writeInt(INDEX_HEADER_MAGIC);
    dataOutput.writeInt(INDEX_HEADER_VERSION);
    dataOutput.writeShort(mTailChunk);
    dataOutput.writeInt(numRecords);
    for (int i=0; i < numRecords; ++i) {
      final long key=mIndexMap.keyAt(i);
      final Record record=mIndexMap.valueAt(i);
      dataOutput.writeLong(key);
      dataOutput.writeShort(record.chunk);
      dataOutput.writeInt(record.offset);
      dataOutput.writeInt(record.size);
      dataOutput.writeInt(record.sizeOnDisk);
      dataOutput.writeLong(record.timestamp);
    }
    dataOutput.close();
    tempFile.renameTo(new File(indexFilePath));
  }
 catch (  Exception e) {
    Log.e(TAG,"Unable to write the index file " + indexFilePath);
    tempFile.delete();
  }
}
 

Example 59

From project android_packages_apps_phone, under directory /src/com/android/phone/sip/.

Source file: SipProfileDb.java

  31 
vote

public void saveProfile(SipProfile p) throws IOException {
synchronized (SipProfileDb.class) {
    if (mProfilesCount < 0)     retrieveSipProfileListInternal();
    File f=new File(mProfilesDirectory + p.getProfileName());
    if (!f.exists())     f.mkdirs();
    AtomicFile atomicFile=new AtomicFile(new File(f,PROFILE_OBJ_FILE));
    FileOutputStream fos=null;
    ObjectOutputStream oos=null;
    try {
      fos=atomicFile.startWrite();
      oos=new ObjectOutputStream(fos);
      oos.writeObject(p);
      oos.flush();
      mSipSharedPreferences.setProfilesCount(++mProfilesCount);
      atomicFile.finishWrite(fos);
    }
 catch (    IOException e) {
      atomicFile.failWrite(fos);
      throw e;
    }
 finally {
      if (oos != null)       oos.close();
    }
  }
}
 

Example 60

From project androlog, under directory /androlog-it/src/test/android/de/akquinet/gomobile/androlog/test/.

Source file: MailReporterTest.java

  31 
vote

public void setUp(){
  try {
    Assert.assertTrue("No SDCard or not the permission to write",Environment.getExternalStorageDirectory().canWrite());
    Properties propsDefault=new Properties();
    propsDefault.setProperty(Constants.ANDROLOG_ACTIVE,"true");
    propsDefault.setProperty(Constants.ANDROLOG_REPORT_ACTIVE,"true");
    propsDefault.setProperty(Constants.ANDROLOG_REPORT_REPORTERS,"de.akquinet.android.androlog.reporter.NoopReporter");
    Properties propsActive=new Properties();
    propsActive.setProperty(Constants.ANDROLOG_ACTIVE,"true");
    propsActive.setProperty(Constants.ANDROLOG_REPORT_ACTIVE,"true");
    propsActive.setProperty(Constants.ANDROLOG_REPORT_REPORTERS,"de.akquinet.android.androlog.reporter.MailReporter");
    propsActive.setProperty(MailReporter.ANDROLOG_REPORTER_MAIL_ADDRESS,"clement.escoffier@gmail.com");
    testContext=new File(Environment.getExternalStorageDirectory(),getContext().getPackageName() + ".properties");
    testContext.createNewFile();
    (new File(Environment.getExternalStorageDirectory(),"tmp")).mkdir();
    FileOutputStream out=new FileOutputStream(testContext);
    propsActive.store(out,"Enable Androlog file");
    out.close();
  }
 catch (  Exception e) {
    e.printStackTrace();
    Assert.fail(e.getMessage());
  }
}
 

Example 61

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: CustomExceptionHandler.java

  31 
vote

private void saveReportToFile(String reportInformation){
  try {
    Log.i(AnkiDroidApp.TAG,"saveReportFile");
    Date currentDate=new Date();
    SimpleDateFormat formatter=new SimpleDateFormat("yyyyMMddHHmmss");
    String filename=String.format("ad-%s.stacktrace",formatter.format(currentDate));
    Log.i(AnkiDroidApp.TAG,"No external storage available");
    FileOutputStream trace=mCurContext.openFileOutput(filename,Context.MODE_PRIVATE);
    trace.write(reportInformation.getBytes());
    trace.close();
    Log.i(AnkiDroidApp.TAG,"report saved");
  }
 catch (  Exception e) {
    Log.i(AnkiDroidApp.TAG,e.toString());
  }
}
 

Example 62

From project ant4eclipse, under directory /org.ant4eclipse.lib.core/src/org/ant4eclipse/lib/core/util/.

Source file: Utilities.java

  31 
vote

/** 
 * Copies one file to another location.
 * @param source The original File which has to be copied. Not <code>null</code>.
 * @param to The destination File which has to be written. Not <code>null</code>.
 */
public static final void copy(File source,File to){
  Assure.isFile("source",source);
  Assure.notNull("to",to);
  FileInputStream instream=null;
  FileOutputStream outstream=null;
  FileChannel readchannel=null;
  FileChannel writechannel=null;
  try {
    instream=new FileInputStream(source);
    outstream=new FileOutputStream(to);
    readchannel=instream.getChannel();
    writechannel=outstream.getChannel();
    readchannel.transferTo(0,readchannel.size(),writechannel);
  }
 catch (  IOException ex) {
    throw new Ant4EclipseException(ex,CoreExceptionCode.COPY_FAILURE,source.getAbsolutePath(),to.getAbsolutePath());
  }
 finally {
    close(readchannel);
    close(writechannel);
    close(instream);
    close(outstream);
  }
}
 

Example 63

From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Commands/.

Source file: cmdRebuild.java

  30 
vote

private boolean downloadSkin(String playerName){
  int len1=0;
  InputStream is=null;
  OutputStream os=null;
  try {
    URL url=new URL("http://s3.amazonaws.com/MinecraftSkins/" + playerName + ".png");
    is=url.openStream();
    os=new FileOutputStream(new File(Core.getInstance().getDataFolder(),"/skins/" + playerName + ".png"));
    byte[] buff=new byte[4096];
    while (-1 != (len1=is.read(buff))) {
      os.write(buff,0,len1);
    }
    os.flush();
  }
 catch (  Exception ex) {
    return false;
  }
 finally {
    if (os != null)     try {
      os.close();
    }
 catch (    IOException ex) {
    }
    if (is != null)     try {
      is.close();
    }
 catch (    IOException ex) {
    }
  }
  return true;
}
 

Example 64

From project Aardvark, under directory /aardvark-core/src/test/java/gw/vark/enums/.

Source file: EnumGenerator.java

  30 
vote

private static void writeEnumTypeToFile(IType iType,File file) throws IOException {
  EnumeratedAttribute ea=(EnumeratedAttribute)iType.getTypeInfo().getConstructor().getConstructor().newInstance();
  StringBuilder sb=new StringBuilder();
  sb.append("package gw.vark.enums\n").append("\n").append("enum ").append(makeName(iType)).append("{\n\n");
  String[] Vals=ea.getValues();
  for (int i=0, ValsLength=Vals.length; i < ValsLength; i++) {
    String string=Vals[i];
    if (string.equals("")) {
      string="NoVal";
    }
    sb.append("  ").append(escape(GosuStringUtil.capitalize(string))).append("(\"").append(GosuEscapeUtil.escapeForGosuStringLiteral(string)).append("\")");
    sb.append(",\n");
  }
  sb.append("\n");
  sb.append("  property get Instance() : " + iType.getName() + " {\n");
  sb.append("    return " + EnumeratedAttribute.class.getName() + ".getInstance("+ iType.getName()+ ", Val) as "+ iType.getName()+ "\n");
  sb.append("  }\n\n");
  sb.append("  var _val : String as Val\n\n");
  sb.append("  private construct( s : String ) { Val = s }\n\n");
  sb.append("}\n");
  String fileName=makeName(iType) + ".gs";
  File actualFile=new File(file,fileName);
  Writer writer=StreamUtil.getOutputStreamWriter(new FileOutputStream(actualFile,false));
  try {
    writer.write(sb.toString());
  }
  finally {
    writer.close();
  }
  _filesInEnums.remove(fileName);
}
 

Example 65

From project agraph-java-client, under directory /src/test/.

Source file: JenaTests.java

  30 
vote

@Test @Category(TestSuites.Prepush.class) public void savingModel_spr37167() throws Exception {
  AGGraphMaker maker=closeLater(new AGGraphMaker(conn));
  AGGraph graph=closeLater(maker.getGraph());
  AGModel model=closeLater(new AGModel(graph));
  Resource bob=model.createResource("http://example.org/people/bob");
  Resource dave=model.createResource("http://example.org/people/dave");
  Property fatherOf=model.createProperty("http://example.org/ontology/fatherOf");
  model.add(bob,fatherOf,dave);
  Resource blankNode=model.createResource();
  Property has=model.createProperty("http://example.org/ontology/has");
  model.add(blankNode,has,dave);
  model.write(closeLater(new FileOutputStream(AGAbstractTest.createTempFile("JenaTest-",".txt"))));
  graph=closeLater(maker.getGraph());
  model=closeLater(new AGModel(graph));
  model.write(closeLater(new FileOutputStream(AGAbstractTest.createTempFile("JenaTest-",".txt"))));
}
 

Example 66

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/helper/.

Source file: CSVHelper.java

  30 
vote

public Uri prepareCSV(Session session) throws IOException {
  OutputStream outputStream=null;
  try {
    File storage=Environment.getExternalStorageDirectory();
    File dir=new File(storage,"aircasting_sessions");
    dir.mkdirs();
    File file=new File(dir,fileName(session.getTitle()));
    outputStream=new FileOutputStream(file);
    Writer writer=new OutputStreamWriter(outputStream);
    CsvWriter csvWriter=new CsvWriter(writer,',');
    csvWriter.write("sensor:model");
    csvWriter.write("sensor:package");
    csvWriter.write("sensor:capability");
    csvWriter.write("Date");
    csvWriter.write("Time");
    csvWriter.write("Timestamp");
    csvWriter.write("geo:lat");
    csvWriter.write("geo:long");
    csvWriter.write("sensor:units");
    csvWriter.write("Value");
    csvWriter.endRecord();
    write(session).toWriter(csvWriter);
    csvWriter.flush();
    csvWriter.close();
    Uri uri=Uri.fromFile(file);
    if (Constants.isDevMode()) {
      Log.i(Constants.TAG,"File path [" + uri + "]");
    }
    return uri;
  }
  finally {
    closeQuietly(outputStream);
  }
}
 

Example 67

From project ajah, under directory /ajah-util/src/main/java/com/ajah/util/io/file/.

Source file: FileUtils.java

  30 
vote

/** 
 * Copies a file to another file by reading and writing the data.
 * @param file The file to read from.
 * @param newFile The file to write to.
 * @return The number of bytes written.
 */
public static long copyFile(final File file,final File newFile){
  InputStream in=null;
  OutputStream out=null;
  long bytes=0;
  try {
    in=new FileInputStream(file);
    out=new FileOutputStream(newFile);
    int read;
    do {
      final byte[] block=new byte[1024];
      read=in.read(block);
      if (read < 0) {
        break;
      }
      bytes+=read;
      out.write(block,0,read);
    }
 while (read >= 0);
    log.fine("Copied " + bytes + " bytes");
    return bytes;
  }
 catch (  final IOException e) {
    if (e.getMessage().endsWith("(Access is denied)")) {
    }
 else     if (e.getMessage().equals("The process cannot access the file because another process has locked a portion of the file")) {
    }
 else {
      log.warning(file.getAbsolutePath());
      log.log(Level.WARNING,e.getMessage(),e);
    }
    return -1;
  }
 finally {
    IOUtils.safeClose(in);
    IOUtils.safeClose(out);
  }
}
 

Example 68

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/main/java/alpha/portal/webapp/controller/.

Source file: FileUploadController.java

  30 
vote

/** 
 * On submit.
 * @param fileUpload the file upload
 * @param errors the errors
 * @param request the request
 * @return the string
 * @throws Exception the exception
 */
@RequestMapping(method=RequestMethod.POST) public String onSubmit(final FileUpload fileUpload,final BindingResult errors,final HttpServletRequest request) throws Exception {
  if (request.getParameter("cancel") != null)   return this.getCancelView();
  if (this.validator != null) {
    this.validator.validate(fileUpload,errors);
    if (errors.hasErrors())     return "fileupload";
  }
  if (fileUpload.getFile().length == 0) {
    final Object[] args=new Object[]{this.getText("uploadForm.file",request.getLocale())};
    errors.rejectValue("file","errors.required",args,"File");
    return "fileupload";
  }
  final MultipartHttpServletRequest multipartRequest=(MultipartHttpServletRequest)request;
  final CommonsMultipartFile file=(CommonsMultipartFile)multipartRequest.getFile("file");
  final String uploadDir=this.getServletContext().getRealPath("/resources") + "/" + request.getRemoteUser()+ "/";
  final File dirPath=new File(uploadDir);
  if (!dirPath.exists()) {
    dirPath.mkdirs();
  }
  final InputStream stream=file.getInputStream();
  final OutputStream bos=new FileOutputStream(uploadDir + file.getOriginalFilename());
  int bytesRead;
  final byte[] buffer=new byte[8192];
  while ((bytesRead=stream.read(buffer,0,8192)) != -1) {
    bos.write(buffer,0,bytesRead);
  }
  bos.close();
  stream.close();
  request.setAttribute("friendlyName",fileUpload.getName());
  request.setAttribute("fileName",file.getOriginalFilename());
  request.setAttribute("contentType",file.getContentType());
  request.setAttribute("size",file.getSize() + " bytes");
  request.setAttribute("location",dirPath.getAbsolutePath() + Constants.FILE_SEP + file.getOriginalFilename());
  final String link=request.getContextPath() + "/resources" + "/"+ request.getRemoteUser()+ "/";
  request.setAttribute("link",link + file.getOriginalFilename());
  return this.getSuccessView();
}
 

Example 69

From project android-database-sqlcipher, under directory /src/net/sqlcipher/database/.

Source file: SQLiteDatabase.java

  30 
vote

private static void loadICUData(Context context,File workingDir){
  try {
    File icuDir=new File(workingDir,"icu");
    if (!icuDir.exists())     icuDir.mkdirs();
    File icuDataFile=new File(icuDir,"icudt46l.dat");
    if (!icuDataFile.exists()) {
      ZipInputStream in=new ZipInputStream(context.getAssets().open("icudt46l.zip"));
      in.getNextEntry();
      OutputStream out=new FileOutputStream(icuDataFile);
      byte[] buf=new byte[1024];
      int len;
      while ((len=in.read(buf)) > 0) {
        out.write(buf,0,len);
      }
      in.close();
      out.flush();
      out.close();
    }
  }
 catch (  Exception e) {
    Log.e(TAG,"Error copying icu data file" + e.getMessage());
  }
}
 

Example 70

From project Android-RTMP, under directory /android-ffmpeg-prototype/src/com/camundo/util/.

Source file: FFMPEGWrapper.java

  30 
vote

/** 
 * Write ffmpeg to data directory and make it executable write in parts because assets can not be bigger then 1MB TODO make it fetch the parts over http, this way consuming less space on the device but...
 * @param overwrite
 * @param target
 * @throws Exception
 */
private void writeFFMPEGToData(boolean overwrite,File target) throws Exception {
  if (!overwrite && target.exists()) {
    return;
  }
  OutputStream out=new FileOutputStream(target);
  byte buf[]=new byte[1024];
  for (  String p : ffmpeg_parts) {
    InputStream inputStream=Camundo.getContext().getAssets().open(p);
    int len;
    while ((len=inputStream.read(buf)) > 0) {
      out.write(buf,0,len);
    }
    inputStream.close();
  }
  out.close();
  Log.d(TAG,executeCommand("/system/bin/chmod 744 " + target.getAbsolutePath()));
  Log.d(TAG,"File [" + target.getAbsolutePath() + "] is created.");
}
 

Example 71

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: Util.java

  30 
vote

static boolean copyFiles(File sourceLocation,File targetLocation) throws IOException {
  if (sourceLocation.equals(targetLocation))   return false;
  if (sourceLocation.isDirectory()) {
    if (!targetLocation.exists()) {
      targetLocation.mkdir();
    }
    String[] children=sourceLocation.list();
    for (int i=0; i < children.length; i++) {
      copyFiles(new File(sourceLocation,children[i]),new File(targetLocation,children[i]));
    }
  }
 else   if (sourceLocation.exists()) {
    InputStream in=new FileInputStream(sourceLocation);
    OutputStream out=new FileOutputStream(targetLocation);
    byte[] buf=new byte[1024];
    int len;
    while ((len=in.read(buf)) > 0) {
      out.write(buf,0,len);
    }
    in.close();
    out.close();
  }
  return true;
}
 

Example 72

From project AndroidSensorLogger, under directory /src/com/sstp/androidsensorlogger/.

Source file: CameraActivity.java

  30 
vote

private static void Save_to_SD(Bitmap bm,String image_name){
  File extStorageDirectory=Environment.getExternalStorageDirectory();
  String meteoDirectory_path=extStorageDirectory + "/space";
  OutputStream outStream=null;
  File file=new File(meteoDirectory_path,"/" + image_name);
  try {
    outStream=new FileOutputStream(file);
    bm.compress(Bitmap.CompressFormat.PNG,100,outStream);
    outStream.flush();
    outStream.close();
    Log.i("Hub","OK, Image Saved to SD");
    Log.i("Hub","height = " + bm.getHeight() + ", width = "+ bm.getWidth());
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
    Log.i("Hub","FileNotFoundException: " + e.toString());
  }
catch (  IOException e) {
    e.printStackTrace();
    Log.i("Hub","IOException: " + e.toString());
  }
}
 

Example 73

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: Util.java

  30 
vote

static boolean copyFiles(File sourceLocation,File targetLocation) throws IOException {
  if (sourceLocation.equals(targetLocation))   return false;
  if (sourceLocation.isDirectory()) {
    if (!targetLocation.exists()) {
      targetLocation.mkdir();
    }
    String[] children=sourceLocation.list();
    for (int i=0; i < children.length; i++) {
      copyFiles(new File(sourceLocation,children[i]),new File(targetLocation,children[i]));
    }
  }
 else   if (sourceLocation.exists()) {
    InputStream in=new FileInputStream(sourceLocation);
    OutputStream out=new FileOutputStream(targetLocation);
    byte[] buf=new byte[1024];
    int len;
    while ((len=in.read(buf)) > 0) {
      out.write(buf,0,len);
    }
    in.close();
    out.close();
  }
  return true;
}
 

Example 74

From project ANNIS, under directory /annis-gui/src/main/java/annis/security/.

Source file: SimpleSecurityManager.java

  30 
vote

@Override public void storeUserProperties(AnnisUser user) throws NamingException, AuthenticationException, IOException {
  File configDir=new File(properties.getProperty(CONFIG_PATH));
  if (configDir.isDirectory()) {
    File usersDir=new File(configDir.getAbsolutePath() + "/users/");
    File fileOfUser=new File(usersDir.getAbsolutePath() + "/" + user.getUserName());
    if (fileOfUser.isFile()) {
      try {
        user.store(new FileOutputStream(fileOfUser,false),"");
      }
 catch (      IOException ex) {
        log.error("",ex);
      }
    }
  }
}
 

Example 75

From project aim3-tu-berlin, under directory /seminar/exercises/datamining/core/src/test/java/de/tuberlin/dima/aim/exercises/.

Source file: HadoopAndPactTestcase.java

  29 
vote

protected static void writeLines(File file,Iterable<String> lines) throws FileNotFoundException {
  PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream(file),Charset.forName("UTF-8")));
  try {
    for (    String line : lines) {
      writer.println(line);
    }
  }
  finally {
    writer.close();
  }
}
 

Example 76

From project airlift, under directory /configuration/src/test/java/io/airlift/configuration/.

Source file: TestConfigurationLoader.java

  29 
vote

@Test public void testLoadsFromFile() throws IOException {
  final File file=File.createTempFile("config",".properties",tempDir);
  PrintStream out=new PrintStream(new FileOutputStream(file));
  try {
    out.print("test: foo");
  }
 catch (  Exception e) {
    out.close();
  }
  System.setProperty("config",file.getAbsolutePath());
  ConfigurationLoader loader=new ConfigurationLoader();
  Map<String,String> properties=loader.loadProperties();
  assertEquals(properties.get("test"),"foo");
  assertEquals(properties.get("config"),file.getAbsolutePath());
  System.getProperties().remove("config");
}
 

Example 77

From project Airports, under directory /src/com/nadmm/airports/notams/.

Source file: NotamService.java

  29 
vote

private void fetchNotams(String icaoCode,File notamFile) throws IOException {
  InputStream in=null;
  String params=String.format(NOTAM_PARAM,icaoCode);
  HttpsURLConnection conn=(HttpsURLConnection)NOTAM_URL.openConnection();
  conn.setRequestProperty("Connection","close");
  conn.setDoInput(true);
  conn.setDoOutput(true);
  conn.setUseCaches(false);
  conn.setConnectTimeout(30 * 1000);
  conn.setReadTimeout(30 * 1000);
  conn.setRequestMethod("POST");
  conn.setRequestProperty("User-Agent","Mozilla/5.0 (X11; U; Linux i686; en-US)");
  conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  conn.setRequestProperty("Content-Length",Integer.toString(params.length()));
  OutputStream faa=conn.getOutputStream();
  faa.write(params.getBytes("UTF-8"));
  faa.close();
  int response=conn.getResponseCode();
  if (response == HttpURLConnection.HTTP_OK) {
    in=conn.getInputStream();
    ArrayList<String> notams=parseNotamsFromHtml(in);
    in.close();
    BufferedOutputStream cache=new BufferedOutputStream(new FileOutputStream(notamFile));
    for (    String notam : notams) {
      cache.write(notam.getBytes());
      cache.write('\n');
    }
    cache.close();
  }
}
 

Example 78

From project ambrose, under directory /common/src/main/java/azkaban/common/utils/.

Source file: Props.java

  29 
vote

/** 
 * Store only those properties defined at this local level
 * @param file The file to write to
 * @throws IOException If the file can't be found or there is an io error
 */
public void storeLocal(File file) throws IOException {
  BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(file));
  try {
    storeLocal(out);
  }
  finally {
    out.close();
  }
}
 

Example 79

From project Android-File-Manager, under directory /src/com/nexes/manager/.

Source file: ApplicationBackup.java

  29 
vote

public void run(){
  BufferedInputStream mBuffIn;
  BufferedOutputStream mBuffOut;
  Message msg;
  int len=mDataSource.size();
  int read=0;
  for (int i=0; i < len; i++) {
    ApplicationInfo info=mDataSource.get(i);
    String source_dir=info.sourceDir;
    String out_file=source_dir.substring(source_dir.lastIndexOf("/") + 1,source_dir.length());
    try {
      mBuffIn=new BufferedInputStream(new FileInputStream(source_dir));
      mBuffOut=new BufferedOutputStream(new FileOutputStream(BACKUP_LOC + out_file));
      while ((read=mBuffIn.read(mData,0,BUFFER)) != -1)       mBuffOut.write(mData,0,read);
      mBuffOut.flush();
      mBuffIn.close();
      mBuffOut.close();
      msg=new Message();
      msg.what=SET_PROGRESS;
      msg.obj=i + " out of " + len+ " apps backed up";
      mHandler.sendMessage(msg);
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
  }
  mHandler.sendEmptyMessage(FINISH_PROGRESS);
}
 

Example 80

From project Android-File-Manager-Tablet, under directory /src/com/nexes/manager/tablet/.

Source file: FileManager.java

  29 
vote

/** 
 * @param old		the file to be copied
 * @param newDir	the directory to move the file to
 * @return
 */
public int copyToDirectory(String old,String newDir){
  File old_file=new File(old);
  File temp_dir=new File(newDir);
  byte[] data=new byte[BUFFER];
  int read=0;
  if (old_file.isFile() && temp_dir.isDirectory() && temp_dir.canWrite()) {
    String file_name=old.substring(old.lastIndexOf("/"),old.length());
    File cp_file=new File(newDir + file_name);
    try {
      BufferedOutputStream o_stream=new BufferedOutputStream(new FileOutputStream(cp_file));
      BufferedInputStream i_stream=new BufferedInputStream(new FileInputStream(old_file));
      while ((read=i_stream.read(data,0,BUFFER)) != -1)       o_stream.write(data,0,read);
      o_stream.flush();
      i_stream.close();
      o_stream.close();
    }
 catch (    FileNotFoundException e) {
      Log.e("FileNotFoundException",e.getMessage());
      return -1;
    }
catch (    IOException e) {
      Log.e("IOException",e.getMessage());
      return -1;
    }
  }
 else   if (old_file.isDirectory() && temp_dir.isDirectory() && temp_dir.canWrite()) {
    String files[]=old_file.list();
    String dir=newDir + old.substring(old.lastIndexOf("/"),old.length());
    int len=files.length;
    if (!new File(dir).mkdir())     return -1;
    for (int i=0; i < len; i++)     copyToDirectory(old + "/" + files[i],dir);
  }
 else   if (!temp_dir.canWrite())   return -1;
  return 0;
}
 

Example 81

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: BinaryDictionaryFileDumper.java

  29 
vote

/** 
 * Copies the data in an input stream to a target file if the magic number matches. If the magic number does not match the expected value, this method throws an IOException. Other usual conditions for IOException or FileNotFoundException also apply.
 * @param input the stream to be copied.
 * @param outputFile an outputstream to copy the data to.
 */
private static void checkMagicAndCopyFileTo(final BufferedInputStream input,final FileOutputStream output) throws FileNotFoundException, IOException {
  final byte[] magicNumberBuffer=new byte[MAGIC_NUMBER.length];
  final int readMagicNumberSize=input.read(magicNumberBuffer,0,MAGIC_NUMBER.length);
  if (readMagicNumberSize < MAGIC_NUMBER.length) {
    throw new IOException("Less bytes to read than the magic number length");
  }
  if (!Arrays.equals(MAGIC_NUMBER,magicNumberBuffer)) {
    throw new IOException("Wrong magic number for downloaded file");
  }
  output.write(MAGIC_NUMBER);
  final byte[] buffer=new byte[FILE_READ_BUFFER_SIZE];
  for (int readBytes=input.read(buffer); readBytes >= 0; readBytes=input.read(buffer))   output.write(buffer,0,readBytes);
  input.close();
}
 

Example 82

From project android-vpn-server, under directory /src/com/android/server/vpn/.

Source file: VpnServiceBinder.java

  29 
vote

void saveStates() throws IOException {
  if (DBG)   Log.d("VpnServiceBinder","     saving states");
  ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(getStateFilePath()));
  oos.writeObject(mService);
  oos.close();
}
 

Example 83

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.

Source file: BinaryDictionaryFileDumper.java

  29 
vote

/** 
 * Copies the data in an input stream to a target file if the magic number matches. If the magic number does not match the expected value, this method throws an IOException. Other usual conditions for IOException or FileNotFoundException also apply.
 * @param input the stream to be copied.
 * @param outputFile an outputstream to copy the data to.
 */
private static void checkMagicAndCopyFileTo(final BufferedInputStream input,final FileOutputStream output) throws FileNotFoundException, IOException {
  final byte[] magicNumberBuffer=new byte[MAGIC_NUMBER.length];
  final int readMagicNumberSize=input.read(magicNumberBuffer,0,MAGIC_NUMBER.length);
  if (readMagicNumberSize < MAGIC_NUMBER.length) {
    throw new IOException("Less bytes to read than the magic number length");
  }
  if (!Arrays.equals(MAGIC_NUMBER,magicNumberBuffer)) {
    throw new IOException("Wrong magic number for downloaded file");
  }
  output.write(MAGIC_NUMBER);
  final byte[] buffer=new byte[FILE_READ_BUFFER_SIZE];
  for (int readBytes=input.read(buffer); readBytes >= 0; readBytes=input.read(buffer))   output.write(buffer,0,readBytes);
  input.close();
}