javatips.net counter

Java Examples for java.io.FileOutputStream

The following java examples will help you to understand the usage of java.io.FileOutputStream. These source code samples are taken from different open source projects.

Example 1
Project: CPP-Programs-master  File: FileDownloader.java View source code
public static void main(String args[]) throws IOException {
    java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://cl.thapar.edu/qp/CH016.pdf").openStream());
    java.io.FileOutputStream fos = new java.io.FileOutputStream("t  est.pdf");
    java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
    byte[] data = new byte[1024];
    int x = 0;
    while ((x = in.read(data, 0, 1024)) >= 0) {
        bout.write(data, 0, x);
    }
    bout.close();
    in.close();
}
Example 2
Project: aetheria-master  File: Downloader.java View source code
/**
	 * Downloads file from an URL and saves it to a path in the local machine
	 * @throws FileNotFoundException, IOException 
	 */
public static void urlToFile(URL url, File path) throws FileNotFoundException, IOException {
    java.io.BufferedInputStream in = new java.io.BufferedInputStream(url.openStream());
    java.io.FileOutputStream fos = new java.io.FileOutputStream(path);
    java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
    byte[] data = new byte[1024];
    int x = 0;
    while ((x = in.read(data, 0, 1024)) >= 0) {
        bout.write(data, 0, x);
    }
    bout.close();
    in.close();
}
Example 3
Project: ares-studio-master  File: Test.java View source code
public static void main(String[] args) {
    ActionInfo ai = new ActionInfo();
    //		ai.properties.get("id").equals(obj)
    //		ai.other = "other";
    File file = new File("ttt.test");
    try {
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
    //XStreamConverter.getInstance().write(fos, ai);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 4
Project: audit-master  File: MainActivity.java View source code
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    try {
        OutputStreamWriter os = null;
        FileOutputStream fos = null;
        String FILEPATH = "/storage/sdcard1/test/";
        fos = new FileOutputStream(FILEPATH + "OutputStreamWrite");
        os = new OutputStreamWriter(fos, "UTF-8");
        new BufferedWriter(os);
        os.write("writeByOutputStreamWrite\n");
        os.close();
        fos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Example 5
Project: deepnighttwo-master  File: CleanDisk.java View source code
/**
     * @param args
     * @throws IOException
     */
public static void main(String[] args) throws IOException {
    byte[] e = new byte[1024 * 1024];
    OutputStream os = new FileOutputStream("/home/mengzang/eeeeeeeeeee");
    int size = 1024 * 110;
    for (int i = 0; i < size; i++) {
        os.write(e);
        if (i % 1024 == 0) {
            System.out.println((i / 1024) + "G");
        }
    }
    System.out.println("Finished.");
}
Example 6
Project: hudson-2.x-master  File: SUTester.java View source code
public static void main(String[] args) throws Throwable {
    SU.execute(StreamTaskListener.fromStdout(), "kohsuke", "bogus", new Callable<Object, Throwable>() {

        public Object call() throws Throwable {
            System.out.println("Touching /tmp/x");
            new FileOutputStream("/tmp/x").close();
            return null;
        }
    });
}
Example 7
Project: hudson-main-master  File: SUTester.java View source code
public static void main(String[] args) throws Throwable {
    SU.execute(StreamTaskListener.fromStdout(), "kohsuke", "bogus", new Callable<Object, Throwable>() {

        public Object call() throws Throwable {
            System.out.println("Touching /tmp/x");
            new FileOutputStream("/tmp/x").close();
            return null;
        }
    });
}
Example 8
Project: jenkins-master  File: SUTester.java View source code
public static void main(String[] args) throws Throwable {
    SU.execute(StreamTaskListener.fromStdout(), "kohsuke", "bogus", new MasterToSlaveCallable<Object, Throwable>() {

        public Object call() throws Throwable {
            System.out.println("Touching /tmp/x");
            new FileOutputStream("/tmp/x").close();
            return null;
        }
    });
}
Example 9
Project: jucy-master  File: CreateXML2FromXML.java View source code
/**
	 * @param args
	 */
public static void main(String[] args) throws Exception {
    Translation trans = new Translation(new File(".."));
    File source = new File("translation/Translations.xml");
    FileInputStream in = new FileInputStream(source);
    trans.readXML(in);
    in.close();
    File target = new File("TranslationTest.xml");
    FileOutputStream fos = new FileOutputStream(target);
    trans.writeXML2(fos);
    fos.close();
}
Example 10
Project: Valamis-master  File: SudokuOut.java View source code
public static void main(String[] args) {
    try {
        FileOutputStream fos = new FileOutputStream("numbers.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        for (int i = 0; i < defaultGame.length; ++i) {
            dos.writeInt(defaultGame[i]);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 11
Project: Aspose_Pdf_Java-master  File: AddingJavaScript.java View source code
public static void main(String[] args) throws IOException {
    // Instantiate a PDF Object
    Pdf pdf = new Pdf();
    // Call the Add method and pass JavaScript statement as an argument, to show Print Dialog
    pdf.getJavaScripts().add("this.print(true);");
    // Call the Add method and JavaScript statement as an argument, to show alert
    pdf.getJavaScripts().add("app.alert(\"hello world\");");
    FileOutputStream out = new FileOutputStream(new File("test.pdf"));
    // Save Pdf Document
    pdf.save(out);
}
Example 12
Project: android-mileage-master  File: DbExportActivity.java View source code
@Override
public String performExport(String inputFile, String outputFile) {
    try {
        FileChannel input = new FileInputStream(inputFile).getChannel();
        FileChannel output = new FileOutputStream(outputFile).getChannel();
        input.transferTo(0, input.size(), output);
        input.close();
        output.close();
        return outputFile;
    } catch (IOException e) {
    }
    return null;
}
Example 13
Project: archive-commons-master  File: GZIPMemberWriterTest.java View source code
public void testWrite() throws IOException {
    String outPath = "/tmp/tmp.gz";
    GZIPMemberWriter gzw = new GZIPMemberWriter(new FileOutputStream(new File(outPath)));
    gzw.write(new ByteArrayInputStream("Here is record 1".getBytes(IAUtils.UTF8)));
    gzw.write(new ByteArrayInputStream("Here is record 2".getBytes(IAUtils.UTF8)));
}
Example 14
Project: Aspose_Cells_Java-master  File: ApacheZoom.java View source code
public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(ApacheZoom.class);
    Workbook wb = new HSSFWorkbook();
    Sheet sheet1 = wb.createSheet("new sheet");
    // 75 percent magnification
    sheet1.setZoom(3, 4);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream(dataDir + "ApacheZoom_Out.xls");
    wb.write(fileOut);
    fileOut.close();
    System.out.println("Process Completed Successfully.");
}
Example 15
Project: Aspose_for_Apache_POI-master  File: ApacheSlideTitle.java View source code
public static void main(String[] args) throws Exception {
    String dataPath = "src/featurescomparison/workingwithslides/setslidetitle/data/";
    SlideShow ppt = new SlideShow();
    Slide slide = ppt.createSlide();
    TextBox title = slide.addTitle();
    title.setText("Hello, World!");
    //save changes 
    FileOutputStream out = new FileOutputStream(dataPath + "Apache_SlideTitle_Out.ppt");
    ppt.write(out);
    out.close();
    System.out.println("Presentation with Title Saved.");
}
Example 16
Project: Aspose_Words_for_Apache_POI-master  File: ApacheExtractImages.java View source code
public static void main(String[] args) throws Exception {
    String dataPath = "src/featurescomparison/workingwithimages/extractimagesfromdocument/data/";
    HWPFDocument doc = new HWPFDocument(new FileInputStream(dataPath + "document.doc"));
    List<Picture> pics = doc.getPicturesTable().getAllPictures();
    for (int i = 0; i < pics.size(); i++) {
        Picture pic = (Picture) pics.get(i);
        FileOutputStream outputStream = new FileOutputStream(dataPath + "Apache_" + pic.suggestFullFileName());
        outputStream.write(pic.getContent());
        outputStream.close();
    }
}
Example 17
Project: Aspose_Words_Java-master  File: ApacheExtractImages.java View source code
public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(ApacheExtractImages.class);
    HWPFDocument doc = new HWPFDocument(new FileInputStream(dataDir + "document.doc"));
    List<Picture> pics = doc.getPicturesTable().getAllPictures();
    for (int i = 0; i < pics.size(); i++) {
        Picture pic = (Picture) pics.get(i);
        FileOutputStream outputStream = new FileOutputStream(dataDir + "Apache_" + pic.suggestFullFileName());
        outputStream.write(pic.getContent());
        outputStream.close();
    }
}
Example 18
Project: BitLib-master  File: FileUtil.java View source code
public static void copy(InputStream in, File file) {
    try {
        OutputStream out = new FileOutputStream(file);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.close();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 19
Project: ChildShareClient-master  File: Utils.java View source code
public static String saveTempFile(Bitmap bm, String filePath, String fileName) throws IOException {
    File dir = new File(filePath);
    if (!dir.exists()) {
        dir.mkdir();
    }
    File file = new File(filePath, fileName);
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
    bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
    bos.flush();
    bos.close();
    return file.getPath();
}
Example 20
Project: Cosmetics-master  File: FileUtils.java View source code
/**
     * Copies a file.
     *
     * @param in   The file to copy.
     * @param file Destination.
     */
public static void copy(InputStream in, File file) {
    try {
        OutputStream out = new FileOutputStream(file);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        out.close();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 21
Project: host-master  File: RepRapUtils.java View source code
public static void copyFile(File sourceFile, File destFile) throws IOException {
    if (!destFile.exists()) {
        destFile.createNewFile();
    }
    FileChannel source = null;
    FileChannel destination = null;
    try {
        source = new FileInputStream(sourceFile).getChannel();
        destination = new FileOutputStream(destFile).getChannel();
        destination.transferFrom(source, 0, source.size());
    } finally {
        if (source != null) {
            source.close();
        }
        if (destination != null) {
            destination.close();
        }
    }
}
Example 22
Project: imageassert-master  File: TemporaryFolderTest.java View source code
@Test
public void testCreateFile() throws Exception {
    TemporaryFolder folder = new TemporaryFolder(this);
    File file = folder.createFile("test.txt");
    assertNotNull(file);
    IOUtils.write("test", new FileOutputStream(file));
    assertTrue(file.exists());
    assertEquals("test", IOUtils.toString(new FileInputStream(file)));
    folder.dispose();
    assertFalse(file.exists());
}
Example 23
Project: imageflow-master  File: MacroExporter.java View source code
public static void main(String[] args) {
    // example UnitList
    GraphController controller = new GraphController();
    controller.setupExample1();
    UnitList unitList = controller.getUnitElements();
    XMLEncoder e;
    try {
        e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
        e.writeObject(new JButton("test"));
        e.close();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
}
Example 24
Project: Justaway-for-Android-Original-master  File: FileUtil.java View source code
public static File writeToTempFile(File cacheDir, InputStream inputStream) {
    if (!cacheDir.exists()) {
        if (!cacheDir.mkdirs()) {
            return null;
        }
    }
    File file = new File(cacheDir, "justaway-temp-" + System.currentTimeMillis() + ".jpg");
    try {
        OutputStream outputStream = new FileOutputStream(file);
        byte[] buffer = new byte[4096];
        int size;
        while (-1 != (size = inputStream.read(buffer))) {
            outputStream.write(buffer, 0, size);
        }
        inputStream.close();
        outputStream.close();
    } catch (Exception e) {
        return null;
    }
    return file;
}
Example 25
Project: kevoree-classloading-framework-master  File: Helper.java View source code
public static File stream2File(InputStream in, String optName) throws IOException {
    File tempF = File.createTempFile("kcl_temp_stream", null);
    tempF.deleteOnExit();
    FileOutputStream fw = new FileOutputStream(tempF);
    byte[] buffer = new byte[1024];
    int len = in.read(buffer);
    while (len != -1) {
        fw.write(buffer, 0, len);
        len = in.read(buffer);
    }
    fw.close();
    return tempF;
}
Example 26
Project: niftyeditor-master  File: FileUtils.java View source code
public static void copyFile(File source, File dest) throws IOException {
    FileChannel inputChannel = null;
    FileChannel outputChannel = null;
    try {
        inputChannel = new FileInputStream(source).getChannel();
        outputChannel = new FileOutputStream(dest).getChannel();
        outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
    } finally {
        inputChannel.close();
        outputChannel.close();
    }
}
Example 27
Project: odroid-master  File: FileSystemUtils.java View source code
public static void saveFile(String path, String name, byte[] data) throws IOException {
    File f = new File(path, name);
    if (f.exists()) {
        f.delete();
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(f);
        fos.write(data);
    } finally {
        if (fos != null) {
            fos.flush();
            fos.close();
        }
    }
}
Example 28
Project: panovit-master  File: TestFifo.java View source code
/**
     * @param args
     */
public static void main(String[] args) {
    PrintWriter pw;
    try {
        pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("/home/jesusr/.config/pianobar/ctl")));
        System.out.println("sending: " + args[0]);
        pw.println(args[0] + "\n");
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Example 29
Project: sandboxes-master  File: FirstDoc.java View source code
public static void main(String[] args) throws IOException, DocumentException {
    URL baseLocation = FirstDoc.class.getProtectionDomain().getCodeSource().getLocation();
    URL location = new URL(baseLocation, "firstdoc.xhtml");
    String outputFile = "firstdoc.pdf";
    OutputStream os = new FileOutputStream(outputFile);
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(location.toExternalForm());
    renderer.layout();
    renderer.createPDF(os);
    os.close();
}
Example 30
Project: scdl-master  File: IOUtil.java View source code
public static void copyFile(final File sourceFile, final File destFile) throws IOException {
    if (!destFile.exists()) {
        destFile.createNewFile();
    }
    FileChannel source = null;
    FileChannel destination = null;
    try {
        source = new FileInputStream(sourceFile).getChannel();
        destination = new FileOutputStream(destFile).getChannel();
        destination.transferFrom(source, 0, source.size());
    } finally {
        if (source != null) {
            source.close();
        }
        if (destination != null) {
            destination.close();
        }
    }
}
Example 31
Project: SCM-master  File: ParseOutputToFile.java View source code
public Boolean parse(InputStream cmdOutput, File fileToWriteTo) throws UnhandledAccurevCommandOutput, IOException {
    final byte[] buffer = new byte[4096];
    try (FileOutputStream os = new FileOutputStream(fileToWriteTo)) {
        int bytesRead = cmdOutput.read(buffer);
        while (bytesRead > 0) {
            os.write(buffer, 0, bytesRead);
            bytesRead = cmdOutput.read(buffer);
        }
    }
    return Boolean.TRUE;
}
Example 32
Project: TagRec-master  File: ResultSerializer.java View source code
public static void serializePredictions(Map<Integer, Map<Integer, Double>> predictions, String filePath) {
    OutputStream file = null;
    try {
        file = new FileOutputStream(filePath);
        OutputStream buffer = new BufferedOutputStream(file);
        ObjectOutput output = new ObjectOutputStream(buffer);
        output.writeObject(predictions);
        output.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 33
Project: traditional-archery-scoreboard-master  File: FileUtils.java View source code
public static void copyFile(final FileInputStream fromFile, final FileOutputStream toFile) throws IOException {
    FileChannel fromChannel = null;
    FileChannel toChannel = null;
    try {
        fromChannel = fromFile.getChannel();
        toChannel = toFile.getChannel();
        fromChannel.transferTo(0, fromChannel.size(), toChannel);
    } finally {
        try {
            if (fromChannel != null) {
                fromChannel.close();
            }
        } finally {
            if (toChannel != null) {
                toChannel.close();
            }
        }
    }
}
Example 34
Project: wayback-machine-master  File: GZIPMemberWriterTest.java View source code
public void testWrite() throws IOException {
    String outPath = "/tmp/tmp.gz";
    GZIPMemberWriter gzw = new GZIPMemberWriter(new FileOutputStream(new File(outPath)));
    gzw.write(new ByteArrayInputStream("Here is record 1".getBytes(IAUtils.UTF8)));
    gzw.write(new ByteArrayInputStream("Here is record 2".getBytes(IAUtils.UTF8)));
}
Example 35
Project: webarchive-commons-master  File: GZIPMemberWriterTest.java View source code
public void testWrite() throws IOException {
    File outFile = File.createTempFile("tmp", ".gz");
    GZIPMemberWriter gzw = new GZIPMemberWriter(new FileOutputStream(outFile));
    gzw.write(new ByteArrayInputStream("Here is record 1".getBytes(IAUtils.UTF8)));
    gzw.write(new ByteArrayInputStream("Here is record 2".getBytes(IAUtils.UTF8)));
}
Example 36
Project: windup-master  File: GraphMLRenderer.java View source code
@Override
public void renderGraph(GraphContext context) {
    Path outputFolder = createOutputFolder(context, "graphml");
    Path outputFile = outputFolder.resolve("graph.graphml");
    GraphMLWriter graphML = new GraphMLWriter(context.getGraph());
    try {
        graphML.outputGraph(new FileOutputStream(outputFile.toFile()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Example 37
Project: musique-master  File: WavWriter.java View source code
public static void wavwriter_writeheaders(java.io.FileOutputStream f, int datasize, int numchannels, int samplerate, int bytespersample, int bitspersample) {
    byte[] buffAsBytes = new byte[4];
    /* write RIFF header */
    buffAsBytes[0] = 82;
    buffAsBytes[1] = 73;
    buffAsBytes[2] = 70;
    // "RIFF" ascii values
    buffAsBytes[3] = 70;
    try {
        f.write(buffAsBytes, 0, 4);
    } catch (java.io.IOException ioe) {
    }
    write_uint32(f, (36 + datasize));
    buffAsBytes[0] = 87;
    buffAsBytes[1] = 65;
    buffAsBytes[2] = 86;
    // "WAVE" ascii values
    buffAsBytes[3] = 69;
    try {
        f.write(buffAsBytes, 0, 4);
    } catch (java.io.IOException ioe) {
    }
    /* write fmt header */
    buffAsBytes[0] = 102;
    buffAsBytes[1] = 109;
    buffAsBytes[2] = 116;
    // "fmt " ascii values
    buffAsBytes[3] = 32;
    try {
        f.write(buffAsBytes, 0, 4);
    } catch (java.io.IOException ioe) {
    }
    write_uint32(f, 16);
    // PCM data
    write_uint16(f, 1);
    write_uint16(f, numchannels);
    write_uint32(f, samplerate);
    // byterate
    write_uint32(f, (samplerate * numchannels * bytespersample));
    write_uint16(f, (numchannels * bytespersample));
    write_uint16(f, bitspersample);
    /* write data header */
    buffAsBytes[0] = 100;
    buffAsBytes[1] = 97;
    buffAsBytes[2] = 116;
    // "data" ascii values
    buffAsBytes[3] = 97;
    try {
        f.write(buffAsBytes, 0, 4);
    } catch (java.io.IOException ioe) {
    }
    write_uint32(f, datasize);
}
Example 38
Project: Tank-master  File: BaseCommonsXmlConfigCpTest.java View source code
/**
     * Run the void checkReload() method test.
     * 
     * @throws Exception
     * 
     * @generatedBy CodePro at 9/3/14 3:44 PM
     */
@Test
public void testCheckReload_1() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");
    fixture.checkReload();
// An unexpected exception was thrown in user code while executing this test:
// java.lang.SecurityException: Cannot write to files while generating test cases
// at
// com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
// at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
// at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
// at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
// at
// org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
// at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
// at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
}
Example 39
Project: cloudml-master  File: CodecTest.java View source code
/**
     * Rigourous Test :-)
     */
public void testApp() {
    Deployment model = completeSensApp().build();
    Deployment model2 = completeCloudBeesPaaS().build();
    Deployment model3 = createBeanstalkDeployment();
    try {
        Codec jsonCodec = new JsonCodec();
        OutputStream streamResult = new java.io.FileOutputStream("sensappTEST.json");
        jsonCodec.save(model, streamResult);
        Codec jsonCodecPaas = new JsonCodec();
        OutputStream streamResultPaaS = new java.io.FileOutputStream("PaaS.json");
        jsonCodecPaas.save(model2, streamResultPaaS);
        Codec jsonCodecPaasBST = new JsonCodec();
        OutputStream streamResultPaaSBST = new java.io.FileOutputStream("Beanstalk.json");
        jsonCodecPaasBST.save(model3, streamResultPaaSBST);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
}
Example 40
Project: ----Data---Storage---master  File: IO.java View source code
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    //     DataOutputStream  dos =new DataOutputStream(new FileOutputStream(new File("/home/wangmeng/zidian")));
    //     dos.writeInt(1000);;
    //     dos.writeInt(78);
    //     dos.close();
    DataInputStream dis = new DataInputStream(new FileInputStream(new File("/home/wangmeng/zidian")));
    System.out.println(new File("/home/wangmeng/zidian").length());
    System.out.println(dis.readInt());
}
Example 41
Project: 101simplejava-master  File: Unparsing.java View source code
public static void copy(String in, String out) throws IOException {
    Recognizer recognizer = recognizeCompany(in);
    Writer writer = new OutputStreamWriter(new FileOutputStream(out));
    String lexeme = null;
    Token current = null;
    while (recognizer.hasNext()) {
        current = recognizer.next();
        lexeme = recognizer.getLexeme();
        // noop
        // write
        writer.write(lexeme);
    }
    writer.close();
}
Example 42
Project: airship-master  File: ResourcesUtil.java View source code
public static void writeResources(Map<String, Integer> resources, File resourcesFile) throws IOException {
    Properties properties = new Properties();
    for (Entry<String, Integer> entry : resources.entrySet()) {
        properties.setProperty(entry.getKey(), String.valueOf(entry.getValue()));
    }
    resourcesFile.getParentFile().mkdirs();
    FileOutputStream out = new FileOutputStream(resourcesFile);
    try {
        properties.store(out, "");
    } finally {
        out.close();
    }
}
Example 43
Project: albert-master  File: DownloadPhotoTest.java View source code
public static void main(String args[]) throws IOException, FileNotFoundException {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod("http://pbs.twimg.com/media/C2bm-eXXcAAd1sc.jpg");
    File storeFile = new File("D:/test2.jpg");
    FileOutputStream output = null;
    try {
        client.executeMethod(get);
        output = new FileOutputStream(storeFile);
        output.write(get.getResponseBody());
        output.close();
    } catch (HttpException e) {
        e.printStackTrace();
    }
}
Example 44
Project: Alfresco-Encryption-Module-master  File: BytestoFile.java View source code
/**
	 * returns a file from a byte array
	 * 
	 */
public static File bytesToFile(byte[] bytes, String path) throws NullPointerException, IOException {
    if (bytes == null)
        throw new NullPointerException();
    if (path == null)
        throw new NullPointerException();
    File file = new File(path);
    FileOutputStream fout;
    fout = new FileOutputStream(file);
    for (int i = 0; i < bytes.length; i++) fout.write(bytes[i]);
    fout.close();
    return file;
}
Example 45
Project: AllArkhamPlugins-master  File: PacketUtils.java View source code
public static void saveUrl(final String filename, final String urlString) throws MalformedURLException, IOException {
    NetworkManager.log.debug("Downloading " + filename + " from " + urlString + "...", PacketUtils.class);
    BufferedInputStream in = null;
    FileOutputStream fout = null;
    try {
        in = new BufferedInputStream(new URL(urlString).openStream());
        fout = new FileOutputStream(filename);
        final byte data[] = new byte[1024];
        int count;
        while ((count = in.read(data, 0, 1024)) != -1) {
            fout.write(data, 0, count);
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (fout != null) {
            fout.close();
        }
    }
    NetworkManager.log.debug("Download of " + filename + " complete!", PacketUtils.class);
}
Example 46
Project: appengine-export-master  File: RtfEmfWriterTest.java View source code
@Test
public void test() throws Exception {
    Document document = new Document();
    FileOutputStream os = new FileOutputStream("target/test.rtf");
    RtfWriter2 writer = RtfWriter2.getInstance(document, os);
    byte[] bytes = IOUtils.getFileBytes(new File("src/test/resources/test.emf"));
    Image image = new ImgEMF(bytes, 500, 500);
    document.open();
    document.add(new Paragraph("Hello World"));
    document.add(image);
    writer.close();
}
Example 47
Project: Aspose_Slides_Java-master  File: ApacheSlideTitle.java View source code
public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(ApacheSlideTitle.class);
    SlideShow ppt = new SlideShow();
    Slide slide = ppt.createSlide();
    TextBox title = slide.addTitle();
    title.setText("Hello, World!");
    //save changes 
    FileOutputStream out = new FileOutputStream(dataDir + "Apache_SlideTitle_Out.ppt");
    ppt.write(out);
    out.close();
    System.out.println("Presentation with Title Saved.");
}
Example 48
Project: Assignments-master  File: Serializer.java View source code
public void SerializeBank(Bank bank) {
    try {
        FileOutputStream fileOut = new FileOutputStream("bank.ser");
        ;
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(bank);
        out.close();
        fileOut.close();
        System.out.printf("Serialized data is saved in bank.ser");
    } catch (IOException i) {
        i.printStackTrace();
    }
}
Example 49
Project: bagpipes-master  File: StreamUtil.java View source code
public static File stream2file(InputStream in) {
    File tempFile = null;
    FileOutputStream out = null;
    try {
        tempFile = File.createTempFile(PREFIX, SUFFIX);
        tempFile.deleteOnExit();
        out = new FileOutputStream(tempFile);
        IOUtils.copy(in, out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return tempFile;
}
Example 50
Project: BBAW_CMS-master  File: ResourceWriter.java View source code
public OutputStream write(final String outputUrl) throws ApplicationException {
    File outputFile = new File(outputUrl);
    File dir = outputFile.getParentFile();
    try {
        dir.mkdirs();
        outputFile.createNewFile();
        return new FileOutputStream(outputFile);
    } catch (IOException e) {
        throw new ApplicationException("Problem while creating output stream for the specified file " + outputUrl);
    }
}
Example 51
Project: brainslug-master  File: BpmnExamples.java View source code
public static void main(String[] args) throws FileNotFoundException {
    //# tag::renderer-example[]
    Format format = Format.JPG;
    JGraphBpmnRenderer renderer = new JGraphBpmnRenderer(new DefaultSkin());
    String fileName = simpleFlow.getName() + "." + format.name();
    FileOutputStream outputFile = new FileOutputStream(fileName);
    renderer.render(simpleFlow, outputFile, format);
//# end::renderer-example[]
}
Example 52
Project: cambodia-master  File: CreateBankFeedsTest.java View source code
public static void main(String[] args) throws Exception {
    List<String> lines = new ArrayList<String>();
    lines.add("hello");
    lines.add("hello");
    lines.add("hello");
    lines.add("hello");
    lines.add("hell你好o");
    FileOutputStream fos = new FileOutputStream(new File("E:\\快�图标\\软件\\aa.txt"), true);
    IOUtils.writeLines(lines, IOUtils.LINE_SEPARATOR, fos, "GBK");
}
Example 53
Project: Car-Cast-master  File: ExportOpml.java View source code
public static void export(List<Subscription> subscriptions, FileOutputStream fileOutputStream) {
    PrintWriter pw = new PrintWriter(fileOutputStream);
    pw.println("<?xml version='1.0' encoding='ISO-8859-1'?>");
    pw.println("<opml version='2.0'>");
    pw.println("<head>");
    pw.println("<title>My CarCast Subscriptions</title>");
    pw.println("</head>");
    pw.println("<body>");
    for (Subscription subscription : subscriptions) {
        pw.print("<outline title=\"");
        pw.print(subscription.name.replaceAll("\"", ""e;").replaceAll("&", "&"));
        pw.print("\" type='rss' version='RSS2' xmlUrl=\"");
        pw.print(subscription.url.replaceAll("\"", ""e;").replaceAll("&", "&"));
        pw.println("\"/>");
    }
    pw.println("</body>");
    pw.println("</opml>");
    pw.close();
}
Example 54
Project: cmop-master  File: Utils.java View source code
/**
	 * 写入报表
	 * 
	 * @param fileName
	 *            生æˆ?报表的路径和文件å??
	 * @param worksheet
	 */
public static void write(String fileName, HSSFSheet worksheet) {
    FileOutputStream stream = null;
    try {
        stream = new FileOutputStream(fileName);
        worksheet.getWorkbook().write(stream);
        // 清除缓存
        stream.flush();
        System.out.println("报表导出完�");
    } catch (Exception e) {
        System.out.println("报表输入失败!");
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Example 55
Project: CodeComb.Mobile.Android-master  File: BitmapHelper.java View source code
public static boolean saveBitmap(File file, Bitmap bitmap) {
    if (file == null || bitmap == null)
        return false;
    try {
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        return bitmap.compress(CompressFormat.JPEG, 100, out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}
Example 56
Project: coding2017-master  File: DownloadUtil.java View source code
public static void createTempFile(String tempName, int len) {
    File file = new File(tempName);
    if (file.exists()) {
        System.out.println("tempfile already created");
        return;
    }
    FileOutputStream temp = null;
    try {
        temp = new FileOutputStream(tempName);
        int length = len;
        byte[] buffer = new byte[1024];
        long times = length / 1024;
        int left = length % 1024;
        for (int i = 0; i < times; i++) {
            temp.write(buffer);
        }
        temp.write(buffer, 0, left);
        System.out.println("tempFile " + tempName + " created");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            temp.flush();
            temp.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Example 57
Project: common-java-cookbook-master  File: JoinFiles.java View source code
public static void main(String[] args) throws Exception {
    InputSupplier<FileInputStream> is = Files.newInputStreamSupplier(new File("data", "test1.txt"));
    InputSupplier<FileInputStream> is2 = Files.newInputStreamSupplier(new File("data", "test2.txt"));
    InputSupplier<InputStream> combined = ByteStreams.join(is, is2);
    OutputSupplier<FileOutputStream> os = Files.newOutputStreamSupplier(new File("output1.data"), false);
    ByteStreams.copy(combined, os);
}
Example 58
Project: compalg-master  File: ExProperties.java View source code
public static void main(String[] args) {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    File file = new File("editor.bila");
    Properties props = new Properties();
    try {
        fis = new FileInputStream(file);
        props.load(fis);
        fis.close();
    } catch (IOException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    //imprime o conteudo do objeto na consola
    props.list(System.out);
    try {
        fos = new FileOutputStream(file);
        props.store(fos, "Configuração do editor");
        fos.close();
    } catch (IOException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Example 59
Project: core-android-master  File: ObjectSerializer.java View source code
public void dump(Object object, String dumpFile) {
    // serialize the object
    try {
        FileOutputStream fout = new FileOutputStream(dumpFile);
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(object);
        oos.close();
        fout.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 60
Project: dashreports-master  File: TextToImageTest.java View source code
public void testGetImageForText() {
    try {
        TextToImage t = new TextToImage();
        byte[] ba = t.getImageForText(new String[] { "Line 1", "Line 2", "Line 3" }, Color.WHITE, Color.BLACK, new Font("Serif", Font.PLAIN, 12), 400, 100, 10, 20, ImageFileFormat.PNG);
        File file = new File("test.png");
        if (file.exists())
            file.delete();
        OutputStream os = new FileOutputStream(file);
        os.write(ba);
        os.flush();
        os.close();
        System.out.println(file.getAbsolutePath());
        assertTrue(ba.length > 10);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Example 61
Project: dbo-2015-master  File: UploadController.java View source code
@Override
public Object handle(Request request, Response response) throws Exception {
    MultipartConfigElement multipartConfigElement = new MultipartConfigElement("/tmp");
    request.raw().setAttribute("org.eclipse.multipartConfig", multipartConfigElement);
    //file is name of the upload form
    Part file = request.raw().getPart("arquivo");
    System.out.println(file.getContentType());
    FileOutputStream fos = new FileOutputStream("/home/jaspion/teste.dat");
    InputStream is = file.getInputStream();
    int b = 0;
    while ((b = is.read()) >= 0) {
        fos.write(b);
    }
    is.close();
    fos.close();
    return null;
}
Example 62
Project: document-management-master  File: CeasrTestApp.java View source code
public static void main(String[] args) throws Exception {
    OutputStream os = new FileOutputStream("/home/maciuch/tmp/topsecret.txt");
    int k = 255;
    os = new CesarOutputStream(os, k);
    os.write("Ala ma psa".getBytes());
    os.close();
    InputStream is = new FileInputStream("/home/maciuch/tmp/topsecret.txt");
    is = new CesarInputStream(is, k);
    int b;
    StringBuilder sb = new StringBuilder();
    while ((b = is.read()) != -1) {
        sb.append((char) b);
    }
    System.out.println(sb.toString());
}
Example 63
Project: droiddraw-master  File: FileCopier.java View source code
public static void copy(File file, File dir, boolean overwrite) throws IOException {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    File out = new File(dir, file.getName());
    if (out.exists() && !overwrite) {
        throw new IOException("File: " + out + " already exists.");
    }
    FileOutputStream fos = new FileOutputStream(out, false);
    byte[] block = new byte[4096];
    int read = bis.read(block);
    while (read != -1) {
        fos.write(block, 0, read);
        read = bis.read(block);
    }
}
Example 64
Project: dronekit-android-master  File: UnZip.java View source code
public static void unZipIt(String fname, File output) throws IOException {
    byte[] buffer = new byte[1024];
    ZipFile zip = new ZipFile(output);
    ZipEntry ze = zip.getEntry(fname);
    InputStream zis = zip.getInputStream(ze);
    File newFile = new File(output.getParent() + "/" + fname);
    FileOutputStream fos = new FileOutputStream(newFile);
    int len;
    while ((len = zis.read(buffer)) > 0) {
        fos.write(buffer, 0, len);
    }
    fos.close();
    zis.close();
    zip.close();
}
Example 65
Project: EMB-master  File: DummyMain.java View source code
public static void main(String[] args) throws Exception {
    System.out.println(Arrays.asList(args));
    File thisFolder = new File(SelfrunTest.class.getResource("/org/embulk/cli/DummyMain.class").toURI()).getParentFile();
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(thisFolder, "args.txt")), Charset.defaultCharset()))) {
        for (String arg : args) {
            writer.write(arg);
            writer.newLine();
        }
    }
}
Example 66
Project: embeddedlinux-jvmdebugger-intellij-master  File: UrlDownloader.java View source code
/**
     * Saves a file to a path
     *
     * @param filename
     * @param urlString
     * @throws IOException
     */
public static void saveUrl(final String filename, final String urlString) throws IOException {
    BufferedInputStream in = null;
    FileOutputStream fout = null;
    try {
        in = new BufferedInputStream(new URL(urlString).openStream());
        fout = new FileOutputStream(filename);
        final byte data[] = new byte[1024];
        int count;
        while ((count = in.read(data, 0, 1024)) != -1) {
            fout.write(data, 0, count);
        }
    } catch (Exception e) {
    } finally {
        if (in != null) {
            in.close();
        }
        if (fout != null) {
            fout.close();
        }
    }
}
Example 67
Project: embulk-master  File: DummyMain.java View source code
public static void main(String[] args) throws Exception {
    System.out.println(Arrays.asList(args));
    File thisFolder = new File(SelfrunTest.class.getResource("/org/embulk/cli/DummyMain.class").toURI()).getParentFile();
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(thisFolder, "args.txt")), Charset.defaultCharset()))) {
        for (String arg : args) {
            writer.write(arg);
            writer.newLine();
        }
    }
}
Example 68
Project: ExcelTool-master  File: TestExtend.java View source code
@Test
public void test() throws WriteException, FileNotFoundException {
    ExtendUtil extendUtil = new ExtendUtil();
    List<TestBean> beanList = new ArrayList<TestBean>();
    for (int i = 0; i < 3000; i++) {
        TestBean bean = new TestBean();
        bean.setIntTest(10000000);
        bean.setStrTest("努力造轮�");
        bean.setTimeTest(new Timestamp(System.currentTimeMillis()));
        beanList.add(bean);
    }
    OutputStream out = new FileOutputStream("d:/yy-export-excel/test3.xls");
    extendUtil.exportByAnnotation(out, beanList);
}
Example 69
Project: FB2OnlineConverter-master  File: EPUBFilter.java View source code
public static void main(String[] args) {
    try {
        File file = new File(args[0]);
        Publication epub = new Publication(file);
        epub.parseAll();
        epub.cascadeStyles();
        System.out.println("Loaded \"" + epub.getDCMetadata("title") + "\"");
        long start = System.currentTimeMillis();
        epub.refactorStyles();
        long end = System.currentTimeMillis();
        System.out.println("Refactored styles in " + (end - start) + "ms");
        //epub.addFonts();
        FileOutputStream out = new FileOutputStream(args[1]);
        epub.serialize(new OCFContainerWriter(out));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 70
Project: filebot-master  File: FileMapper.java View source code
@Override
public OutputStream getStream(File entry) throws IOException {
    File outputFile = getOutputFile(entry);
    File outputFolder = outputFile.getParentFile();
    // create parent folder if necessary
    if (!outputFolder.isDirectory() && !outputFolder.mkdirs()) {
        throw new IOException("Failed to create folder: " + outputFolder);
    }
    return new FileOutputStream(outputFile);
}
Example 71
Project: find-sec-bugs-master  File: PathTraversal.java View source code
public static void main(String[] args) throws IOException, URISyntaxException {
    String input = args.length > 0 ? args[0] : "../../../../etc/password";
    new File(input);
    new File("test/" + input, "misc.jpg");
    new RandomAccessFile(input, "r");
    new File(new URI(args[0]));
    new FileReader(input);
    new FileInputStream(input);
    new FileWriter(input);
    new FileWriter(input, true);
    new FileOutputStream(input);
    new FileOutputStream(input, true);
    // false positive test
    new RandomAccessFile("safe", args[0]);
    new FileWriter("safe".toUpperCase());
    new File(new URI("safe"));
}
Example 72
Project: flash8-swfparser-master  File: FileWriter.java View source code
protected void dumpFile(String fileName, String content) {
    try {
        FileOutputStream file = new FileOutputStream(outputDirectory + "/" + fileName);
        file.write(content.getBytes());
        file.flush();
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Error creating file " + fileName);
    }
}
Example 73
Project: freehep-io-master  File: RunLengthOutputStreamTest.java View source code
/**
	 * Test method for 'org.freehep.util.io.RunLengthOutputStream.write()'
	 * 
	 * @throws Exception
	 *             if ref file cannot be found
	 */
public void testWrite() throws Exception {
    File testFile = new File(testDir, "Quote.txt");
    File outFile = new File(outDir, "Quote.rnl");
    File refFile = new File(refDir, "Quote.rnl");
    RunLengthOutputStream out = new RunLengthOutputStream(new FileOutputStream(outFile));
    FileInputStream in = new FileInputStream(testFile);
    int b;
    while ((b = in.read()) >= 0) {
        out.write(b);
    }
    in.close();
    out.close();
    Assert.assertEquals(refFile, outFile, true);
}
Example 74
Project: fudannlp-master  File: Unlabeled.java View source code
public static void processUnLabeledData(String input, String output) throws Exception {
    FileInputStream is = new FileInputStream(input);
    //		is.skip(3); //skip BOM
    BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf8"));
    OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(output), "utf8");
    while (true) {
        String sent = r.readLine();
        if (sent == null)
            break;
        String[][] ss = String2Sequence.genSequence(sent);
        String s = MyStrings.toString(ss, "\n");
        w.write(s);
    }
    w.close();
    r.close();
}
Example 75
Project: fuse4j-master  File: DumpJVMLdPath.java View source code
public static void main(String[] args) throws IOException {
    String[] libDirs = System.getProperty("java.library.path", "").split(":");
    StringBuffer sb = new StringBuffer("LDPATH :=");
    for (int i = 0; i < libDirs.length; i++) sb.append(" -L").append(libDirs[i]);
    if (args.length == 0)
        System.out.println(sb.toString());
    else {
        PrintStream out = new PrintStream(new FileOutputStream(args[0]));
        out.println(sb.toString());
        out.close();
    }
}
Example 76
Project: hadoop-test-master  File: NoOpAction.java View source code
public static void main(String args[]) {
    try {
        File file = new File(System.getProperty(OOZIE_ACTION_OUTPUT_PROPERTIES));
        Properties props = new Properties();
        props.setProperty(OUTPUT_NUMBER, args[0]);
        OutputStream os = new FileOutputStream(file);
        props.store(os, "");
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 77
Project: hudson.core-master  File: SUTester.java View source code
public static void main(String[] args) throws Throwable {
    SU.execute(StreamTaskListener.fromStdout(), "kohsuke", "bogus", new Callable<Object, Throwable>() {

        public Object call() throws Throwable {
            System.out.println("Touching /tmp/x");
            new FileOutputStream("/tmp/x").close();
            return null;
        }
    });
}
Example 78
Project: Icon-Request-Tool-master  File: ZipUtil.java View source code
public static void zip(File zipFile, File... files) throws Exception {
    ZipOutputStream out = null;
    InputStream is = null;
    try {
        out = new ZipOutputStream(new FileOutputStream(zipFile));
        for (File fi : files) {
            out.putNextEntry(new ZipEntry(fi.getName()));
            is = new FileInputStream(fi);
            int read;
            byte[] buffer = new byte[2048];
            while ((read = is.read(buffer)) != -1) out.write(buffer, 0, read);
            FileUtil.closeQuietely(is);
            out.closeEntry();
        }
    } finally {
        FileUtil.closeQuietely(is);
        FileUtil.closeQuietely(out);
    }
}
Example 79
Project: ils-master  File: QRCodeGenerator.java View source code
/**
	 * Erzeugt fuer eine als Parameter uebergebene URL einen
	 * QR Code und gibt diesen als FileOutputstream zurueck
	 * @param url
	 * @return
	 */
public FileOutputStream createQRCode(String url) {
    ByteArrayOutputStream out = QRCode.from(url).to(ImageType.PNG).stream();
    try {
        FileOutputStream fileOut = new FileOutputStream(new File("\\Code.png"));
        fileOut.write(out.toByteArray());
        fileOut.flush();
        fileOut.close();
        return fileOut;
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    return null;
}
Example 80
Project: ipss-odm-master  File: BPA_500kv_NoDC_Test.java View source code
@Test
public void bpaTestCase() throws Exception {
    IODMAdapter adapter = new BPAAdapter();
    //		IODMAdapter adapter =new PSSEV30Adapter();
    //EQ_0907_500KV-N0DC.dat
    assertTrue(adapter.parseInputFile("EQ_0907_500KV-NoDC.dat"));
    AclfModelParser parser = (AclfModelParser) adapter.getModel();
    parser.stdout();
//		String xml=parser.toXmlDoc(false);
//		FileOutputStream out=new FileOutputStream(new File("500kvNoDC_BPA_ODM_0408.xml"));
//		out.write(xml.getBytes());
//		out.flush();
//		out.close();
}
Example 81
Project: IronCount-master  File: ObjectSerializerTest.java View source code
@Test
public void writeHandlerToDisk() throws Exception {
    SerializedHandler h = new SerializedHandler();
    ObjectSerializer instance = new ObjectSerializer();
    byte[] result = instance.serializeObject(h);
    java.io.BufferedOutputStream bi = new BufferedOutputStream(new FileOutputStream(new File("/tmp/abd")));
    bi.write(result);
    bi.close();
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("/tmp/abd")));
}
Example 82
Project: jacorb-master  File: Server.java View source code
public static void main(String[] args) throws Exception {
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
    org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
    poa.the_POAManager().activate();
    ServerImpl s = new ServerImpl();
    org.omg.CORBA.Object o = poa.servant_to_reference(s);
    PrintWriter ps = new PrintWriter(new FileOutputStream(new File(args[0])));
    ps.println(orb.object_to_string(o));
    ps.close();
    while (args.length == 2 || !s.getShutdown()) {
        Thread.sleep(1000);
    }
    orb.shutdown(true);
}
Example 83
Project: janala2-gradle-master  File: FileLogger.java View source code
@Override
public void run() {
    try {
        outputStream.close();
        outputStream = new ObjectOutputStream(new FileOutputStream(Config.instance.traceAuxFileName));
        outputStream.writeObject(ClassNames.getInstance());
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 84
Project: janala2-master  File: FileLogger.java View source code
@Override
public void run() {
    try {
        outputStream.close();
        outputStream = new ObjectOutputStream(new FileOutputStream(Config.instance.traceAuxFileName));
        outputStream.writeObject(ClassNames.getInstance());
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 85
Project: japicmp-master  File: JarUtil.java View source code
public static void createJarFile(Path jarFileName, CtClass... ctClasses) throws IOException, CannotCompileException {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    try (JarOutputStream jarStream = new JarOutputStream(new FileOutputStream(jarFileName.toString()), manifest)) {
        for (CtClass ctClass : ctClasses) {
            JarEntry entry = new JarEntry(ctClass.getSimpleName() + ".class");
            jarStream.putNextEntry(entry);
            byte[] bytecode = ctClass.toBytecode();
            jarStream.write(bytecode, 0, bytecode.length);
            jarStream.closeEntry();
        }
    }
}
Example 86
Project: JAVA-KOANS-master  File: CopyFileOperation.java View source code
public void sourceToDestination(File src, File dest) throws IOException {
    InputStream in = new FileInputStream(src);
    if (!dest.getParentFile().exists()) {
        dest.getParentFile().mkdirs();
    }
    OutputStream out = new FileOutputStream(dest);
    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}
Example 87
Project: javacuriosities-master  File: GenerateLexer.java View source code
public static void main(String[] args) {
    try {
        URL resource = Thread.currentThread().getContextClassLoader().getResource("lexer.jlex");
        JLex.Main.main(new String[] { resource.getPath() });
        File currentDirectory = new File(".");
        FileOutputStream fileOutputStream = new FileOutputStream(new File(currentDirectory.getCanonicalPath() + "/src/main/java/" + LEXER_PACKAGE.replaceAll("\\.", "/") + "/ArithmeticLexer.java"));
        Path path = Paths.get(resource.getPath() + ".java");
        Files.copy(path, fileOutputStream);
        Files.delete(path);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 88
Project: jcifs-krb5-master  File: WaitNamedPipe.java View source code
public static void main(String[] argv) throws Exception {
    if (argv.length < 2) {
        throw new IllegalArgumentException("args: <smburl> <filedatatosend> <filetowriterecvdata>");
    }
    byte[] b = new byte[65535];
    FileInputStream fin = new FileInputStream(argv[1]);
    FileOutputStream fos = new FileOutputStream(argv[2]);
    SmbNamedPipe pipe = new SmbNamedPipe(argv[0], SmbNamedPipe.PIPE_TYPE_RDWR);
    OutputStream out = pipe.getNamedPipeOutputStream();
    InputStream in = pipe.getNamedPipeInputStream();
    int n = fin.read(b);
    System.out.println("writing " + n + " bytes");
    out.write(b, 0, n);
    n = in.read(b);
    System.out.println("read " + n + " bytes");
    fos.write(b, 0, n);
    fin.close();
    fos.close();
    out.close();
}
Example 89
Project: jcifs-log4j-master  File: WaitNamedPipe.java View source code
public static void main(String[] argv) throws Exception {
    if (argv.length < 2) {
        throw new IllegalArgumentException("args: <smburl> <filedatatosend> <filetowriterecvdata>");
    }
    byte[] b = new byte[65535];
    FileInputStream fin = new FileInputStream(argv[1]);
    FileOutputStream fos = new FileOutputStream(argv[2]);
    SmbNamedPipe pipe = new SmbNamedPipe(argv[0], SmbNamedPipe.PIPE_TYPE_RDWR);
    OutputStream out = pipe.getNamedPipeOutputStream();
    InputStream in = pipe.getNamedPipeInputStream();
    int n = fin.read(b);
    System.out.println("writing " + n + " bytes");
    out.write(b, 0, n);
    n = in.read(b);
    System.out.println("read " + n + " bytes");
    fos.write(b, 0, n);
    fin.close();
    fos.close();
    out.close();
}
Example 90
Project: jcifs-master  File: WaitNamedPipe.java View source code
public static void main(String[] argv) throws Exception {
    if (argv.length < 2) {
        throw new IllegalArgumentException("args: <smburl> <filedatatosend> <filetowriterecvdata>");
    }
    byte[] b = new byte[65535];
    FileInputStream fin = new FileInputStream(argv[1]);
    FileOutputStream fos = new FileOutputStream(argv[2]);
    SmbNamedPipe pipe = new SmbNamedPipe(argv[0], SmbNamedPipe.PIPE_TYPE_RDWR);
    OutputStream out = pipe.getNamedPipeOutputStream();
    InputStream in = pipe.getNamedPipeInputStream();
    int n = fin.read(b);
    System.out.println("writing " + n + " bytes");
    out.write(b, 0, n);
    n = in.read(b);
    System.out.println("read " + n + " bytes");
    fos.write(b, 0, n);
    fin.close();
    fos.close();
    out.close();
}
Example 91
Project: jframe-master  File: FrameMain.java View source code
/**
     * @param args
     * @throws InterruptedException
     * @throws IOException
     */
public static void main(String[] args) throws InterruptedException, IOException {
    System.out.println("Frame main start");
    for (String arg : args) {
        System.out.println(arg);
    }
    Date s = new Date();
    while (true) {
        Thread.sleep(2000);
        Date d = new Date();
        File f = new File("/home/dzh/temp/test/process.txt");
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(d.toString().getBytes());
        fos.close();
        System.out.println("write date: " + d.toString());
        if (d.getTime() - s.getTime() > 10000) {
            break;
        }
    }
}
Example 92
Project: jpexs-decompiler-master  File: Test.java View source code
public static void main(String[] args) throws Exception {
    PDFJob job = new PDFJob(new FileOutputStream("test.pdf"));
    PageFormat pf = new PageFormat();
    pf.setOrientation(PageFormat.PORTRAIT);
    Paper p = new Paper();
    //A4
    p.setSize(210, 297);
    pf.setPaper(p);
    BufferedImage img = ImageIO.read(new File("earth.jpg"));
    int w = 200;
    for (int i = 0; i < 10; i++) {
        Graphics g = job.getGraphics();
        g.drawImage(img, 0, 0, w, w, null);
        g.dispose();
    }
    job.end();
}
Example 93
Project: jvmnotebook-master  File: AsmBuilder.java View source code
public static final void main(final String[] args) throws Exception {
    System.out.println("Asm Builder");
    final ClassWriter writer = new ClassWriter(0);
    // gets the bytecode of the Example class, and loads it dynamically
    final byte[] code = writer.toByteArray();
    final OutputStream stream = new FileOutputStream("Test.class");
    final BufferedOutputStream buf = new BufferedOutputStream(stream);
    try {
        buf.write(code, 0, code.length);
        buf.flush();
    } finally {
        buf.close();
    }
    System.out.println("Done, class written to disk.");
}
Example 94
Project: koa-master  File: CopyFileOperation.java View source code
public void sourceToDestination(File src, File dest) throws IOException {
    InputStream in = new FileInputStream(src);
    if (!dest.getParentFile().exists()) {
        dest.getParentFile().mkdirs();
    }
    OutputStream out = new FileOutputStream(dest);
    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}
Example 95
Project: LearningCommunity-master  File: UploadMultipartFileTest.java View source code
public void saveFile(byte[] multipartFile, String path) {
    String filename = "aa.txt";
    File file = null;
    try {
        file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        byte[] buffer = multipartFile;
        FileOutputStream fStream = new FileOutputStream(path + "/" + filename);
        fStream.write(buffer);
        fStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 96
Project: liferay-ide-master  File: Main.java View source code
public static void copyFile(File source, File dest) {
    try {
        FileChannel in = new FileInputStream(source).getChannel();
        if (!dest.getParentFile().exists())
            dest.getParentFile().mkdirs();
        FileChannel out = new FileOutputStream(dest).getChannel();
        in.transferTo(0, in.size(), out);
        in.close();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 97
Project: like_netease_news-master  File: FileCopyUtils.java View source code
public static boolean copyDB(InputStream in) {
    File dbFile = new File(NewsApplication.DB_PATH + NewsApplication.DB_NAME);
    if (!dbFile.getParentFile().exists()) {
        dbFile.getParentFile().mkdirs();
    }
    if (!dbFile.exists()) {
        OutputStream out = null;
        try {
            out = new FileOutputStream(dbFile);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = in.read(buffer)) != -1) {
                out.write(buffer, 0, len);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}
Example 98
Project: lumify-master  File: AdminApiExt.java View source code
public void uploadOntology(InputStream file) throws ApiException, IOException {
    // TODO has to be a better way than writing to a local file.
    File f = File.createTempFile("uploadOntology", ".xml");
    try {
        FileOutputStream out = new FileOutputStream(f);
        try {
            IOUtils.copy(file, out);
        } finally {
            out.close();
        }
        uploadOntology(f);
    } finally {
        f.delete();
    }
}
Example 99
Project: millipede-master  File: RandomFile.java View source code
public static void writeRandomFile(String fileName, double size) throws IOException {
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    long currentpos = 0;
    Random r = new Random();
    while (currentpos < size) {
        byte[] rndB = new byte[Main.CHUNK_LENGTH];
        r.nextBytes(rndB);
        out.write(rndB);
        currentpos = currentpos + rndB.length;
        out.flush();
    }
    out.flush();
    out.close();
}
Example 100
Project: mp4parser-master  File: Repair.java View source code
public static void main(String[] args) throws IOException {
    Movie m = MovieCreator.build("c:\\content\\ffmpeg.mp4");
    DefaultMp4Builder defaultMp4Builder = new DefaultMp4Builder();
    Container c = defaultMp4Builder.build(m);
    FileOutputStream fos = new FileOutputStream("C:\\content\\out.mp4");
    WritableByteChannel wbc = Channels.newChannel(fos);
    c.writeContainer(wbc);
}
Example 101
Project: MySnippetRepo-master  File: MyPictureCallback.java View source code
@Override
public void onPictureTaken(byte[] data, Camera camera) {
    try {
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        File file = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg");
        FileOutputStream output = new FileOutputStream(file);
        bitmap.compress(CompressFormat.JPEG, 100, output);
        output.close();
        camera.stopPreview();
        camera.startPreview();
        MyService.bm = bitmap;
    } catch (Exception e) {
        e.printStackTrace();
    }
}