List of usage examples for java.io File setWritable
public boolean setWritable(boolean writable)
From source file:com.lazerycode.selenium.filedownloader.FileDownloader.java
/** * Perform the file/image download.// w w w . j a va 2 s . co m * * @param element * @param attribute * @return * @throws IOException * @throws NullPointerException */ private String downloader(WebElement element, String attribute, String Filename) throws IOException, NullPointerException, URISyntaxException { String fileToDownloadLocation = element.getAttribute(attribute); if (fileToDownloadLocation.trim().equals("")) throw new NullPointerException("The element you have specified does not link to anything!"); URL fileToDownload = new URL(fileToDownloadLocation); //changed by Raul File downloadedFile = new File(Filename); //+ " fileToDownload.getFile().replaceFirst("/|\\\\", "").replace("?", "")); if (downloadedFile.canWrite() == false) downloadedFile.setWritable(true); HttpClient client = new DefaultHttpClient(); BasicHttpContext localContext = new BasicHttpContext(); //LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState); if (this.mimicWebDriverCookieState) { localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies())); } HttpGet httpget = new HttpGet(fileToDownload.toURI()); HttpParams httpRequestParameters = httpget.getParams(); httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects); httpget.setParams(httpRequestParameters); // LOG.info("Sending GET request for: " + httpget.getURI()); HttpResponse response = client.execute(httpget, localContext); this.httpStatusOfLastDownloadAttempt = response.getStatusLine().getStatusCode(); //LOG.info("HTTP GET request status: " + this.httpStatusOfLastDownloadAttempt); //LOG.info("Downloading file: " + downloadedFile.getName()); FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile); response.getEntity().getContent().close(); String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath(); // LOG.info("File downloaded to '" + downloadedFileAbsolutePath + "'"); return downloadedFileAbsolutePath; }
From source file:org.datavec.api.records.writer.impl.LibSvmRecordWriterTest.java
@Test public void testNDArrayWritables() throws Exception { INDArray arr2 = Nd4j.zeros(2);/*from w w w . j a v a2 s . co m*/ arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 13); arr3.putScalar(1, 14); arr3.putScalar(2, 15); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new IntWritable(4)); File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "13.0,14.0,15.0,4 1:1.0 2:11.0 3:12.0 4:2.0 5:3.0"; try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:org.datavec.api.records.writer.impl.SVMLightRecordWriterTest.java
@Test public void testNDArrayWritables() throws Exception { INDArray arr2 = Nd4j.zeros(2);/* ww w . j ava2 s . c o m*/ arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 13); arr3.putScalar(1, 14); arr3.putScalar(2, 15); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new IntWritable(4)); File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "13.0,14.0,15.0,4 1:1.0 2:11.0 3:12.0 4:2.0 5:3.0"; try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:org.datavec.api.records.writer.impl.LibSvmRecordWriterTest.java
@Test public void testNDArrayWritablesMultilabel() throws Exception { INDArray arr2 = Nd4j.zeros(2);/*from w w w. j av a 2s .co m*/ arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 0); arr3.putScalar(1, 1); arr3.putScalar(2, 0); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new DoubleWritable(1)); File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "2,4 1:1.0 2:11.0 3:12.0 4:2.0 5:3.0"; try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setBoolean(LibSvmRecordWriter.MULTILABEL, true); configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:org.datavec.api.records.writer.impl.SVMLightRecordWriterTest.java
@Test public void testNDArrayWritablesMultilabel() throws Exception { INDArray arr2 = Nd4j.zeros(2);//from w w w .j a v a 2 s .c o m arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 0); arr3.putScalar(1, 1); arr3.putScalar(2, 0); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new DoubleWritable(1)); File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "2,4 1:1.0 2:11.0 3:12.0 4:2.0 5:3.0"; try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setBoolean(SVMLightRecordWriter.MULTILABEL, true); configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:org.datavec.api.records.writer.impl.LibSvmRecordWriterTest.java
@Test public void testNDArrayWritablesZeroIndex() throws Exception { INDArray arr2 = Nd4j.zeros(2);/*w w w . ja v a 2s . com*/ arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 0); arr3.putScalar(1, 1); arr3.putScalar(2, 0); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new DoubleWritable(1)); File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "1,3 0:1.0 1:11.0 2:12.0 3:2.0 4:3.0"; try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setBoolean(LibSvmRecordWriter.ZERO_BASED_INDEXING, true); // NOT STANDARD! configWriter.setBoolean(LibSvmRecordWriter.ZERO_BASED_LABEL_INDEXING, true); // NOT STANDARD! configWriter.setBoolean(LibSvmRecordWriter.MULTILABEL, true); configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:org.datavec.api.records.writer.impl.SVMLightRecordWriterTest.java
@Test public void testNDArrayWritablesZeroIndex() throws Exception { INDArray arr2 = Nd4j.zeros(2);//w w w . j ava2 s . c o m arr2.putScalar(0, 11); arr2.putScalar(1, 12); INDArray arr3 = Nd4j.zeros(3); arr3.putScalar(0, 0); arr3.putScalar(1, 1); arr3.putScalar(2, 0); List<Writable> record = Arrays.asList((Writable) new DoubleWritable(1), new NDArrayWritable(arr2), new IntWritable(2), new DoubleWritable(3), new NDArrayWritable(arr3), new DoubleWritable(1)); File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt"); tempFile.setWritable(true); tempFile.deleteOnExit(); if (tempFile.exists()) tempFile.delete(); String lineOriginal = "1,3 0:1.0 1:11.0 2:12.0 3:2.0 4:3.0"; try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) { Configuration configWriter = new Configuration(); configWriter.setBoolean(SVMLightRecordWriter.ZERO_BASED_INDEXING, true); // NOT STANDARD! configWriter.setBoolean(SVMLightRecordWriter.ZERO_BASED_LABEL_INDEXING, true); // NOT STANDARD! configWriter.setBoolean(SVMLightRecordWriter.MULTILABEL, true); configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0); configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 3); FileSplit outputSplit = new FileSplit(tempFile); writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner()); writer.write(record); } String lineNew = FileUtils.readFileToString(tempFile).trim(); assertEquals(lineOriginal, lineNew); }
From source file:hudson.Util.java
/** * Makes the given file writable./*from w ww . j a v a 2 s . com*/ */ @IgnoreJRERequirement private static void makeWritable(File f) { // try chmod. this becomes no-op if this is not Unix. try { Chmod chmod = new Chmod(); chmod.setProject(new Project()); chmod.setFile(f); chmod.setPerm("u+w"); chmod.execute(); } catch (BuildException e) { LOGGER.log(Level.INFO, "Failed to chmod " + f, e); } // also try JDK6-way of doing it. try { f.setWritable(true); } catch (NoSuchMethodError e) { // not JDK6 } }
From source file:org.docx4j.template.io.WordprocessingMLPackageWriter.java
/** * {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} html * @param wmlPackage {@link WordprocessingMLPackage} * @param outFile /*w w w .j a va2 s . co m*/ * @return {@link File} docx * @throws IOException IO * @throws Docx4JException Docx4j */ public File writeToHtml(WordprocessingMLPackage wmlPackage, File outFile) throws IOException, Docx4JException { Assert.notNull(wmlPackage, " wmlPackage is not specified!"); Assert.isTrue(outFile.exists(), " outFile is not founded !"); OutputStream output = null; try { String imageTargetUri = Docx4jProperties .getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_HTML_IMAGETARGETURI, "images"); File[] files = outFile.listFiles(new OutputDirFilterHandler(imageTargetUri)); if (files.length != 1) { File imageDir = new File(outFile, imageTargetUri); imageDir.setWritable(true); imageDir.setReadable(true); imageDir.mkdir(); } //? output = new FileOutputStream(outFile); //Html HTMLSettings htmlSettings = Docx4J.createHTMLSettings(); htmlSettings.setImageDirPath(outFile.getParent()); htmlSettings.setImageTargetUri(imageTargetUri); htmlSettings.setWmlPackage(wmlPackage); //d htmlSettings.setHyperlinkHandler(getHyperlinkHandler()); htmlSettings.setScriptElementHandler(getScriptElementHandler()); htmlSettings.setStyleElementHandler(getStyleElementHandler()); Docx4jProperties.setProperty(Docx4jConstants.DOCX4J_PARAM_04, true); //Docx4J.toHTML(settings, outputStream, flags); //Docx4J.toHTML(wmlPackage, imageDirPath, imageTargetUri, outputStream); Docx4J.toHTML(htmlSettings, output, Docx4J.FLAG_EXPORT_PREFER_XSL); } finally { IOUtils.closeQuietly(output); } return outFile; }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testExistingLockedZipFile() throws Exception { exception.expect(IOException.class); File aTargetFile = File.createTempFile("target/Z9-input", ".zip"); aTargetFile.setWritable(false); String aTargetFilename = aTargetFile.getAbsolutePath(); ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("src/test/resources/testFiles/")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:src/test/resources/testFiles/input.csv"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertTrue(new File(aTargetFilename).exists()); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(1)).incrementReadCount(); verify(aStepContribution, times(1)).incrementWriteCount(1); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();//from ww w. java 2 s. c o m }