/** * Read all the data from the input stream up until the first end of file character, add this * data to a byte array, and close the input stream; returns the byte array */ public static byte[] inputStreamToBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); }
protected IFile saveFile(File aFile, IProject p) throws IOException { IFile iFile = p.getFile(aFile.getURI()); WorkbenchByteArrayOutputStream out = new WorkbenchByteArrayOutputStream(iFile); ArchiveUtil.copy(aFile.getInputStream(), out); return iFile; }
public LoadStrategy createTempZipFileStrategyIfPossible(String uri, LoadStrategy parent) { if (!ArchiveUtil.shouldUseTempDirectoryForRead()) return null; try { java.io.File tempFile = ArchiveUtil.createTempFile(uri); DeleteOnExitUtility.markForDeletion(tempFile); InputStream in = parent.getInputStream(uri); OutputStream out = new FileOutputStream(tempFile); ArchiveUtil.copy(in, out); return new TempZipFileLoadStrategyImpl(tempFile); } catch (IOException ex) { ArchiveUtil.inform(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.make_temp_file_WARN_, (new Object[]{uri})) + ex.getLocalizedMessage()); // = "Warning: Unable to create temp file for {0}. This will impact performance." } return null; }
public void save(File aFile, InputStream in) throws SaveFailureException { try { String entryName = aFile.getURI(); if (aFile.isDirectoryEntry() && !entryName.endsWith("/"))//$NON-NLS-1$ entryName = entryName + '/'; ZipEntry entry = new ZipEntry(entryName); if (aFile.getLastModified() > 0) entry.setTime(aFile.getLastModified()); getZipOutputStream().putNextEntry(entry); if (!aFile.isDirectoryEntry()) { org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.copy(in, getZipOutputStream()); } getZipOutputStream().closeEntry(); } catch (IOException iox) { throw new SaveFailureException(aFile.getURI(), iox); } }
/** * @see com.ibm.etools.archive.impl.SaveStrategyImpl */ public void save(org.eclipse.jst.j2ee.commonarchivecore.internal.File aFile, InputStream in) throws SaveFailureException { String entryName = aFile.getURI(); if (aFile.isDirectoryEntry()) mkdirs(entryName); else { try { OutputStream out = getUriConverter().createOutputStream(URI.createURI(entryName)); org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.copy(in, out); } catch (IOException iox) { throw new SaveFailureException(aFile.getURI(), iox); } } }
/** * @see com.ibm.etools.archive.impl.SaveStrategyImpl */ public void save(org.eclipse.jst.j2ee.commonarchivecore.internal.File aFile, InputStream in) throws SaveFailureException { String entryName = aFile.getURI(); if (aFile.isDirectoryEntry()) mkdirs(entryName); else { try { OutputStream out = getUriConverter().createOutputStream(URI.createURI(entryName)); ArchiveUtil.copy(in, out); setTimestampAfterSaving(aFile); } catch (IOException iox) { throw new SaveFailureException(aFile.getURI(), iox); } } }