Saves the file returned in the response body as a file in the cache directory

@param responseBody containing file
@return resulting file, or null if there were any IO exceptions
967168
private File saveAsFile(ResponseBody responseBody) {
    if (responseBody == null) {
      return null;
    }

    try {
      File file = new File(destDirectory + File.separator + fileName + retrieveUniqueId() + "." + extension);
      InputStream inputStream = null;
      OutputStream outputStream = null;

      try {
        inputStream = responseBody.byteStream();
        outputStream = new FileOutputStream(file);
        byte[] buffer = new byte[4096];
        int numOfBufferedBytes;

        while ((numOfBufferedBytes = inputStream.read(buffer)) != END_OF_FILE_DENOTER) {
          outputStream.write(buffer, 0, numOfBufferedBytes);
        }

        outputStream.flush();
        return file;

      } catch (IOException exception) {
        return null;

      } catch (Exception exception) {
        return null;

      } finally {
        if (inputStream != null) {
          inputStream.close();
        }

        if (outputStream != null) {
          outputStream.close();
        }
      }

    } catch (IOException exception) {
      return null;
    }
  }
851119
protected AbstractMetadataResolver getMetadataResolverFromResponse(final HttpResponse response, final File backupFile) throws Exception {
        val entity = response.getEntity();
        val result = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
        val path = backupFile.toPath();
        LOGGER.trace("Writing metadata to file at [{}]", path);
        try (val output = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
            IOUtils.write(result, output);
            output.flush();
        }
        EntityUtils.consume(entity);
        return new InMemoryResourceMetadataResolver(backupFile, configBean);
    }
191748
def save(filename, path, params={})
      payload = get! path, nil, params
      File.write filename, payload.response.body
    end
911999
@Transactional
	public void save(Response response) {
		Response merged = em.merge(response);
		em.flush();
		response.setId(merged.getId());
	}
499282
public RequestResponse setResponseData(byte[] responseData) {
        this.responseData = responseData;
        try {
            responseJson = responseData != null ? SerializationUtils.readJson(responseData) : null;
        } catch (Exception e) {
            responseJson = null;
            LOGGER.error(e.getMessage(), e);
        }
        return this;
    }
1185250
def _write_response_to_file(self, response):
        
        with open(self.local_path, 'r+b') as outfile:  # open file for read/write (no truncate)
            outfile.seek(self.seek_amt)
            for chunk in response.iter_content(chunk_size=self.bytes_per_chunk):
                if chunk:  # filter out keep-alive chunks
                    outfile.write(chunk)
                    self._on_bytes_read(len(chunk))
899221
public Response<File> toFileResponse(Path path) {
        File file = path.toFile();
        this.writeToFile(file);
        return new Response<>(this.url, this.statusCode, this.cookies, this.headers, file);
    }
342455
public static base_response save(nitro_service client, cacheobject resource) throws Exception {
		cacheobject saveresource = new cacheobject();
		saveresource.locator = resource.locator;
		return saveresource.perform_operation(client,"save");
	}
1162888
private String getFileFromCache(String filename) {
        LRUCache.CacheEntry<String, T> cachedTemplate = cache.get(filename);

        if (cachedTemplate == null) {
            return null;
        }

        return cache.get(filename).raw;
    }
334440
public PactDslRequestWithoutPath body(JSONObject body) {
        requestBody = OptionalBody.body(body.toString().getBytes());
        if (!requestHeaders.containsKey(CONTENT_TYPE)) {
            requestHeaders.put(CONTENT_TYPE, Collections.singletonList(ContentType.APPLICATION_JSON.toString()));
        }
        return this;
    }
521738
public static void responseFile(HttpServletResponse response, String local, boolean isDownloaded) throws IOException {
        if (Checker.isExists(local)) {
            File file = new File(local);
            try (FileInputStream in = new FileInputStream(file); ServletOutputStream os = response.getOutputStream()) {
                byte[] b;
                while (in.available() > 0) {
                    b = in.available() > 1024 ? new byte[1024] : new byte[in.available()];
                    in.read(b, 0, b.length);
                    os.write(b, 0, b.length);
                }
                os.flush();
            }
            if (isDownloaded) {
                String fn = new String(file.getName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
                response.setHeader("Content-Disposition", "attachment;filename=" + fn);
            }
        } else {
            response.setStatus(404);
        }
    }
562643
@RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<E> save(HttpServletRequest request) {

        final String simpleClassName = getEntityClass().getSimpleName();
        final String errorMessagePrefix = "Error when saving entity of type "
            + simpleClassName + ": ";

        BufferedReader reader = null;
        // read and parse the json request body
        try {
            reader = request.getReader();

            E entity = objectMapper.readValue(reader, getEntityClass());

            // ID value MUST be null to assure that
            // saveOrUpdate will save and not update
            final Integer id = entity.getId();
            if (id != null) {
                LOG.error(errorMessagePrefix + "ID value is set to " + id
                    + ", but MUST be null");
                return new ResponseEntity<E>(HttpStatus.BAD_REQUEST);
            }

            this.service.saveOrUpdate(entity);
            LOG.trace("Created " + simpleClassName + " with ID " + entity.getId());
            return new ResponseEntity<E>(entity, HttpStatus.CREATED);
        } catch (Exception e) {
            LOG.error(errorMessagePrefix + e.getMessage());
            return new ResponseEntity<E>(HttpStatus.BAD_REQUEST);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
1126059
protected RequestBody setCompressedBody(byte[] bodyBytes) {
        if (bodyBytes.length < MIN_JSON_LENGTH_TO_COMPRESS)
            return null;
        byte[] encodedBytes = Utils.compressByGzip(bodyBytes);
        if (encodedBytes == null || encodedBytes.length >= bodyBytes.length)
            return null;
        return RequestBody.create(JSON, encodedBytes);
    }
950370
public void extractInPlace(StubMapping stubMapping) {
        byte[] body = stubMapping.getResponse().getByteBody();
        HttpHeaders responseHeaders = stubMapping.getResponse().getHeaders();
        String extension = ContentTypes.determineFileExtension(
            stubMapping.getRequest().getUrl(),
            responseHeaders != null ? responseHeaders.getContentTypeHeader() : ContentTypeHeader.absent(),
            body);

        String bodyFileName = SafeNames.makeSafeFileName(stubMapping, extension);

         // used to prevent ambiguous method call error for withBody()
        String noStringBody = null;
        byte[] noByteBody = null;

        stubMapping.setResponse(
            ResponseDefinitionBuilder
                .like(stubMapping.getResponse())
                .withBodyFile(bodyFileName)
                .withBody(noStringBody)
                .withBody(noByteBody)
                .withBase64Body(null)
                .build()
        );

        fileSource.writeBinaryFile(bodyFileName, body);
    }
4652
public Object restore(String savePoint, Class<?> objClass)
   {
	String location = whereIs(savePoint, objClass);
	
	Object cacheObject = CacheFarm.getCache().get(location);
	if(cacheObject  != null)
	   return cacheObject;
	
	cacheObject = IO.deserialize(new File(location));
	CacheFarm.getCache().put(location, cacheObject);
	
	return cacheObject;
   }
934425
public static File saveToTempFolder(Part part) throws IOException {
    String filename = getOriginalFileName(part);
    if (filename == null) {
      return null;
    }

    File file = new File(FileUtils.getTempDirectory(), filename);
    FileCopyUtils.copy(part.getInputStream(), new FileOutputStream(file));

    return file;
  }
565230
protected function cacheResponse(RequestInterface $request, ResponseInterface $response)
    {
        $cacheItem = $this->createCacheItem($this->createKeyFromRequest($request));
        $value = $response->getBody()->__toString();
        $cacheItem->set($value);

        $this
            ->getCacheItemPool()
            ->save($cacheItem);
    }