/** * Writes the content of an input stream to a style resource, without validation * * @param info Style info object, containing details about the style format and location * @param input The style contents * @throws IOException if there was an error persisting the style */ private void writeStyleRaw(StyleInfo info, InputStream input) throws IOException { try { catalog.getResourcePool().writeStyle(info, input); } finally { IOUtils.closeQuietly(input); } }
/** * Reads content from the body of a request and writes it to a file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * * @return The file object representing the newly written file. * * @throws IOException Any I/O errors that occur. * * TODO: move this to IOUtils. */ public static File handleBinUpload(String fileName, File directory, boolean deleteDirectoryContent, Request request) throws IOException { final File newFile = new File(directory, fileName); if (deleteDirectoryContent && newFile.exists()) { FileUtils.cleanDirectory(directory); } final ReadableByteChannel source =request.getEntity().getChannel(); final FileChannel outputChannel = IOUtils.getOuputChannel(newFile); IOUtils.copyChannel(1024*1024, source,outputChannel ); IOUtils.closeQuietly(source); IOUtils.closeQuietly(outputChannel); return newFile; }
IOUtils.closeQuietly(zipOutputStream); IOUtils.closeQuietly(bufferedOutputStream); IOUtils.closeQuietly(byteArrayOutputStream);
IOUtils.closeQuietly(is);
@Test public void testUploadImageMosaic() throws Exception { URL zip = MockData.class.getResource("watertemp.zip"); InputStream is = null; byte[] bytes; try { is = zip.openStream(); bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is); } MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/gs/coveragestores/watertemp/file.imagemosaic", bytes, "application/zip"); assertEquals(201, response.getStatus()); // check the response contents String content = response.getContentAsString(); Document d = dom(new ByteArrayInputStream(content.getBytes())); XMLAssert.assertXpathEvaluatesTo("watertemp", "//coverageStore/name", d); XMLAssert.assertXpathEvaluatesTo("ImageMosaic", "//coverageStore/type", d); // check the coverage is actually there CoverageStoreInfo storeInfo = getCatalog().getCoverageStoreByName("watertemp"); assertNotNull(storeInfo); CoverageInfo ci = getCatalog().getCoverageByName("watertemp"); assertNotNull(ci); assertEquals(storeInfo, ci.getStore()); }
@Test public void testHarvestNotAllowedOnSimpleCoverageStore() throws Exception { // add bluemarble getTestData().addDefaultRasterLayer(SystemTestData.TASMANIA_BM, getCatalog()); // Harvesting of the Mosaic URL zipHarvest = MockData.class.getResource("harvesting.zip"); // Extract a Byte array from the zip file InputStream is = null; byte[] bytes; try { is = zipHarvest.openStream(); bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is); } // Create the POST request MockHttpServletRequest request = createRequest( RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores/BlueMarble"); request.setMethod("POST"); request.setContentType("application/zip"); request.setContent(bytes); request.addHeader("Content-type", "application/zip"); // Get The response MockHttpServletResponse response = dispatch(request); // not allowed assertEquals(405, response.getStatus()); }
bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is); bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is);
bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is);
bytes = IOUtils.toByteArray(is); } finally { IOUtils.closeQuietly(is);