Save file to website's resource directory.

@param handle Weblog handle to save to
@param name Name of file to save
@param size Size of file to be saved
@param is Read file from input stream
161812
private void saveMediaFile(final String name, final String contentType, final long size, final InputStream is) throws AtomException {

        final byte[] buffer = new byte[8192];
        int bytesRead = 0;

        final File dirPath = new File(getEntryMediaPath(name));
        if (!dirPath.getParentFile().exists()) {
            dirPath.getParentFile().mkdirs();
        }
        OutputStream bos = null;
        try {
            bos = new FileOutputStream(dirPath.getAbsolutePath());
            while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
                bos.write(buffer, 0, bytesRead);
            }
        } catch (final Exception e) {
            throw new AtomException("ERROR uploading file", e);
        } finally {
            try {
                bos.flush();
                bos.close();
            } catch (final Exception ignored) {
            }
        }

    }
20936
public void addNameUrl(final String name, final String url) 
	throws IOException {
		doPostMethod(ResourceFileLocationDBServlet.ADD_OPERATION, name, url);
	}
1150445
protected void saveFile(SebEvent event, File file, String name, String extension) {
		event.saveFile(file, getListenerFileName(name), extension);
	}
871534
public static void save(byte[] bytes,String filePath,String fileName) throws IOException {
        Path path = Paths.get(filePath, fileName);
        mkirDirs(path.getParent());
        String pathStr = path.toString();
        File file = new File(pathStr);
        write(bytes,file);
    }
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
1166181
def set_cached_resource_size(self, resource_name, size):
        
        size_data = json_dumps({"size": size, "recorded_time": time()})
        self.cache.set(
            "SIZE:%s" % resource_name, size_data,
            ex=self.size_cache_timeout)
        return
1178878
function _read(size) {
  /* jshint validthis: true */
  if (this.finished) {
    this.push(null);
  } else {
    if (!this.reading) {
      this.reading = true;
      var context = {
        stream: this
      };
      this.call.recvMessageWithContext(context);
    }
  }
}
977219
def save(self, name):
        
        with open(name, 'wb+') as f:
            while True:
                buf = self._fileobj.read()
                if not buf:
                    break
                f.write(buf)
860981
def save_resource(self, name, resource, pushable=False):
        ''

        if pushable:
            self.pushable_resources[name] = resource
        else:
            self.resources[name] = resource
1025201
def save_error(message)
      path = error_file_path
      FileUtils.mkdir_p File.dirname(path)
      File.open(path, 'w') { |f| f.write message }
      warn "API request failed! log can be found in #{path}"
    end
884844
private final void addHandle(WSJdbcConnection handle) throws ResourceException {
        (numHandlesInUse < handlesInUse.length - 1 ? handlesInUse : resizeHandleList())[numHandlesInUse++] = handle;
        if (!inRequest && dsConfig.get().enableBeginEndRequest)
            try {
                inRequest = true;
                mcf.jdbcRuntime.beginRequest(sqlConn);
            } catch (SQLException x) {
                FFDCFilter.processException(x, getClass().getName(), "548", this);
                throw new DataStoreAdapterException("DSA_ERROR", x, getClass());
            }
    }
1176001
protected void process(HttpServletRequest request, HttpServletResponse response, String fileName)
            throws IOException {
        // TODO put this html code in a template
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");
        response.setStatus(200);
        FileBackedStringBuffer buffer = new FileBackedStringBuffer();

        buffer.append("<html><head><title>");
        buffer.append(request.getRemoteHost());
        buffer.append("</title><script type=text/javascript>");
        buffer.append("function submitform() { document.myform.submit(); } </script>");
        buffer.append("</head><body><H1>View Logs on - ");
        buffer.append(request.getRemoteHost()).append("</H1>");

        if (isLogsDirectoryEmpty()) {
            buffer.append("<br>No Logs available.</br></body></html>");
            dumpStringToStream(buffer, response.getOutputStream());
            return;
        }
        buffer.append(appendMoreLogsLink(fileName, request.getRequestURL().toString()));
        buffer.append(renderLogFileContents(fileName));
        buffer.append("</body></html>");
        dumpStringToStream(buffer, response.getOutputStream());
    }
1314043
public void saveAs(String name, boolean isAppend) throws IOException {
        //log.debug("SaveAs - name: {} append: {}", name, isAppend);
        // get connection to check if client is still streaming
        IStreamCapableConnection conn = getConnection();
        if (conn == null) {
            throw new IOException("Stream is no longer connected");
        }
        // one recording listener at a time via this entry point
        if (recordingListener == null) {
            // XXX Paul: Revisit this section to allow for implementation of custom IRecordingListener
            //IRecordingListener listener = (IRecordingListener) ScopeUtils.getScopeService(conn.getScope(), IRecordingListener.class, RecordingListener.class, false);
            // create a recording listener
            IRecordingListener listener = new RecordingListener();
            //log.debug("Created: {}", listener);
            // initialize the listener
            if (listener.init(conn, name, isAppend)) {
                // get decoder info if it exists for the stream
                IStreamCodecInfo codecInfo = getCodecInfo();
                //log.debug("Codec info: {}", codecInfo);
                if (codecInfo instanceof StreamCodecInfo) {
                    StreamCodecInfo info = (StreamCodecInfo) codecInfo;
                    IVideoStreamCodec videoCodec = info.getVideoCodec();
                    //log.debug("Video codec: {}", videoCodec);
                    if (videoCodec != null) {
                        //check for decoder configuration to send
                        IoBuffer config = videoCodec.getDecoderConfiguration();
                        if (config != null) {
                            //log.debug("Decoder configuration is available for {}", videoCodec.getName());
                            VideoData videoConf = new VideoData(config.asReadOnlyBuffer());
                            try {
                                //log.debug("Setting decoder configuration for recording");
                                listener.getFileConsumer().setVideoDecoderConfiguration(videoConf);
                            } finally {
                                videoConf.release();
                            }
                        }
                    } else {
                        log.debug("Could not initialize stream output, videoCodec is null.");
                    }
                    IAudioStreamCodec audioCodec = info.getAudioCodec();
                    //log.debug("Audio codec: {}", audioCodec);
                    if (audioCodec != null) {
                        //check for decoder configuration to send
                        IoBuffer config = audioCodec.getDecoderConfiguration();
                        if (config != null) {
                            //log.debug("Decoder configuration is available for {}", audioCodec.getName());
                            AudioData audioConf = new AudioData(config.asReadOnlyBuffer());
                            try {
                                //log.debug("Setting decoder configuration for recording");
                                listener.getFileConsumer().setAudioDecoderConfiguration(audioConf);
                            } finally {
                                audioConf.release();
                            }
                        }
                    } else {
                        log.debug("No decoder configuration available, audioCodec is null.");
                    }
                }
                // set as primary listener
                recordingListener = new WeakReference<IRecordingListener>(listener);
                // add as a listener
                addStreamListener(listener);
                // start the listener thread
                listener.start();
            } else {
                log.warn("Recording listener failed to initialize for stream: {}", name);
            }
        } else {
            log.debug("Recording listener already exists for stream: {} auto record enabled: {}", name, automaticRecording);
        }
    }
836319
public final void save(File file) throws IOException {
        _entryFile = file;
        Chronos c = new Chronos();
        DataWriter out = new FastDataWriter(file);

        try {
            out.open();

            // Save entry head
            out.writeLong(STORAGE_VERSION); // write the entry file version
            out.writeLong(_minScn);
            out.writeLong(_maxScn);
            out.writeInt(size());

            // Save entry body
            saveDataSection(out);

            // Save entry tail.
            out.writeLong(_minScn);
            out.writeLong(_maxScn);
        } finally {
            out.close();
        }
        
        if(_log.isInfoEnabled()) {
            _log.info("Saved entry: minScn=" + _minScn + " maxScn=" + _maxScn + " size=" + size() + " file=" + file.getName() + " in " + c.getElapsedTime());
        }
    }
412064
public void downloadFile(int fileId, java.io.File target, FileSize size)
			throws IOException {
		WebResource builder = getResourceFactory()
				.getFileResource("/" + fileId);
		if (size != null) {
			builder = builder.path("/" + size.name().toLowerCase());
		}
		byte[] data = builder.get(byte[].class);
		FileUtils.writeByteArrayToFile(target, data);
	}
116586
protected void saveFile(SebEvent event, String content, String name, String extension) {
		event.saveFile(content, getListenerFileName(name), extension);
	}
1062146
protected void setLogFileSize(long newFileSize)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass
                        , "setLogFileSize"
                        , "newFileSize=" + newFileSize + "(long)"
                            );

        // Note where we are in the log file.
        long initialFilePosition = filePosition;

        synchronized (newFileSizeRequestLock) {
            // Force the new file size to be a whole number of pages.
            this.newFileSize = (newFileSize / pageSize) * pageSize;
            newFileSizeRequested = true;
            newFileSizeException = null;
            logFileSizeRequested = newFileSize;
            // We have not yet seen the log file wrap.
            boolean wrapped = false;

            // Keep requesting checkpoints until the start and end of the log data are both 
            // before the new end of the log, without the user log data wrapping round the 
            // end of the logFile.
            while (newFileSizeRequested) {

                // Check there is still some chance of fitting the current log into the new one.
                // and that we have not wrapped round the log file without succeeding.
                long fileSpaceAvailable = getLogFileSpaceLeft();
                long newFileSpaceAvailable = fileSpaceAvailable - fileLogHeader.fileSize + newFileSize;
                float newOcupancy = (float) 1.0 - (float) (newFileSpaceAvailable) / (float) (newFileSize);
                if (newOcupancy > objectManagerState.logFullPostCheckpointThreshold
                    || wrapped) {
                    newFileSizeRequested = false;
                    logFileSizeRequested = 0;
                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this,
                                   cclass,
                                   "setLogFileSize",
                                   new Object[] { new Long(fileLogHeader.fileSize),
                                                 new Long(newFileSize),
                                                 new Float(newOcupancy) });
                    throw new LogFileSizeTooSmallException(this
                                                           , fileLogHeader.fileSize
                                                           , newFileSize
                                                           , fileSpaceAvailable
                                                           , newOcupancy
                                                           , objectManagerState.logFullPostCheckpointThreshold);
                } // if (   (fileSpaceLeft...

                if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
                    trace.debug(this,
                                cclass,
                                "setLogFileSize",
                                new Object[] { new Long(filePosition),
                                              new Long(initialFilePosition) });

                // If we have wrapped round the log file, give up after the next attempt to satisfy the 
                // request. 
                if (filePosition < initialFilePosition)
                    wrapped = true;

                // We have released the lock on writingFlushSet set so now we can request a checkpoint and
                // see if we are successful.
                objectManagerState.waitForCheckpoint(true);

                // Speed up moving the filePosition by writing a reasonable ammount of data.
                // The folowing is dangerous because it can cause the request to fail if we 
                // are trying to reduce the log file size close to the minimum possible. 
//        PaddingLogRecord paddingLogRecord = new PaddingLogRecord(logBufferSize/2);
//        writeNext(paddingLogRecord
//                 ,0
//                 ,true
//                 );

            } // while (newFileSizeRequested...

            logFileSizeRequested = 0;
        } // synchronized (newFileSizeRequestLock).                                            

        if (newFileSizeException != null) {
            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this, cclass
                           , "setLogFileSize"
                           , "via PermanentIOException newFileSizeException=" + newFileSizeException + "(PermanentIOException)"
                                );
            throw newFileSizeException;
        }

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass
                       , "setLogFileSize"
                            );
    }