/*
(non-Javadoc)

@see
net.jawr.web.resource.bundle.ResourceBundlesHandler#writeBundleTo(java
.lang.String, java.io.Writer)
340046
@Override
	public void writeBundleTo(String bundlePath, Writer writer) throws ResourceNotFoundException {
		
		String text = (String) cacheMgr.get(TEXT_CACHE_PREFIX + bundlePath);
		try {
			// If it's not cached yet
			if (null == text) {
				String charsetName = rsHandler.getConfig().getResourceCharset().name();
				ByteArrayOutputStream baOs = new ByteArrayOutputStream();
				WritableByteChannel wrChannel = Channels.newChannel(baOs);
				Writer tempWriter = Channels.newWriter(wrChannel, charsetName);
				rsHandler.writeBundleTo(bundlePath, tempWriter);
				text = baOs.toString(charsetName);
				cacheMgr.put(TEXT_CACHE_PREFIX + bundlePath, text);
			}

			// Write the text to the outputstream
			writer.write(text);
			writer.flush();

		} catch (IOException e) {
			throw new BundlingProcessException("Unexpected IOException writing bundle[" + bundlePath + "]", e);
		}finally {
			IOUtils.close(writer);
		}
	}
1112783
public void writeDetailLine(Record registration, StreamOut out, boolean bResourceListBundle)
    {
        String strKey = registration.getField(Registration.KEY_VALUE).toString();
        String strValue = registration.getField(Registration.OBJECT_VALUE).toString();
        strValue = ResourcesUtilities.fixPropertyValue(strValue, bResourceListBundle);
        if (bResourceListBundle)
            out.writeit("\t{\"" + strKey + "\", " + strValue + "}");
        else
            out.writeit(ResourcesUtilities.fixPropertyKey(strKey) + "=" + strValue);
    }
328196
@Override
  public void write(ByteAppendable os, char ch)
    throws IOException
  {
    if (ch < 0x80) {
      os.write(ch);
    }
    else if (ch < 0x800) {
      os.write((0xc0 + (ch >> 6)));
      os.write((0x80 + (ch & 0x3f)));
    }
    else {
      os.write((0xe0 + (ch >> 12)));
      os.write((0x80 + ((ch >> 6) & 0x3f)));
      os.write((0x80 + (ch & 0x3f)));
    }
  }
925708
public void writeExternal(PofWriter writer)
            throws IOException {
        writer.writeString(0, name);
        writer.writeLong(1, last);
    }
1203788
@Override
	protected void performGlobalBundleLinksRendering(BundleRendererContext ctx, Writer out, boolean debugOn)
			throws IOException {

		renderGlobalLinks = true;
		super.performGlobalBundleLinksRendering(ctx, out, debugOn);
		renderGlobalLinks = false;
	}
909388
protected function writeBundleFile($bundlePath, $data)
    {
        $dir = dirname($bundlePath);

        if (!file_exists($dir)) {
            mkdir($dir, 0777, true);
        }

        if (false === file_put_contents($bundlePath, $data, LOCK_EX)) {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException('Cannot write cache file to "' . $bundlePath . '"');
            // @codeCoverageIgnoreEnd
        }

        return filemtime($bundlePath);
    }
502857
@Override
  public void writeExternal(ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeObject(conservativeApproximation);
  }
225791
public void xmlWriteOn(FormattedWriter writer) throws IOException
  {
    writer.newLine();
    writer.taggedValue("remoteMEUuid", remoteMEUuid);
    writer.newLine();
    writer.taggedValue("streamID", streamID);
    writer.newLine();
    writer.taggedValue("initialData", initialData);
    writer.newLine();
    writer.taggedValue("type", type);
  }
67238
private void writeObject(java.io.ObjectOutputStream out)
                    throws IOException
    {
        out.defaultWriteObject();
        // write out the header information
        out.write(eyecatcher);
        out.writeShort(platform);
        out.writeShort(versionID);

        // write out the data
        out.writeObject(server);
        out.writeObject(allWrappers);
        out.writeInt(chunkSize);
    }
28206
@Override
	public void streamBundleTo(String bundlePath, OutputStream out) throws ResourceNotFoundException {

		// Remove prefix, which are used only in production mode
		String path = PathNormalizer.removeVariantPrefixFromPath(bundlePath);
		ReadableByteChannel data = null;
		try {
			if (liveProcessBundles.contains(path)) {

				Reader rd = null;
				try {
					rd = resourceBundleHandler.getResourceBundleReader(path);
					StringReader strRd = processInLive(rd);
					StringWriter strWriter = new StringWriter();
					IOUtils.copy(strRd, strWriter);

					ByteArrayOutputStream bos = new ByteArrayOutputStream();
					try (GZIPOutputStream gzOut = new GZIPOutputStream(bos)) {
						byte[] byteData = strWriter.getBuffer().toString().getBytes(config.getResourceCharset().name());
						gzOut.write(byteData, 0, byteData.length);
					}
					ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
					data = Channels.newChannel(bis);
				} finally {
					IOUtils.close(rd);
				}

			} else {
				data = resourceBundleHandler.getResourceBundleChannel(path);
			}

			WritableByteChannel outChannel = Channels.newChannel(out);
			IOUtils.copy(data, outChannel);

		} catch (IOException e) {
			throw new BundlingProcessException("Unexpected IOException writing bundle [" + path + "]", e);
		} finally {
			IOUtils.close(data);
		}
	}
1332642
public static void writeTo(String html, Writer writer) throws IOException {
		int index = html.indexOf('#');
		if (index == -1) {
			writer.write(html);
		} else {
			final ResourceBundle resourceBundle = getResourceBundle();
			int begin = 0;
			while (index != -1) {
				writer.write(html, begin, index - begin);
				final int nextIndex = html.indexOf('#', index + 1);
				final String key = html.substring(index + 1, nextIndex);
				writer.write(resourceBundle.getString(key));
				begin = nextIndex + 1;
				index = html.indexOf('#', begin);
			}
			writer.write(html, begin, html.length() - begin);
		}
	}
1044684
public void write(Bean bean, boolean rootType, Appendable output) throws IOException {
        if (bean == null) {
            throw new NullPointerException("bean");
        }
        this.output = output;
        this.rootBean = bean;
        this.basePackage = (rootType ? bean.getClass().getPackage().getName() + "." : null);
        
        String type = rootBean.getClass().getName();
        writeHeader();
        output.append('<').append(BEAN);
        if (rootType) {
            appendAttribute(output, TYPE, type);
        }
        output.append('>').append(settings.getNewLine());
        writeBean(rootBean, settings.getIndent());
        output.append('<').append('/').append(BEAN).append('>').append(settings.getNewLine());
    }
395180
@Override
  public void write(JsonWriterImpl out, char []value)
  {
    out.write(String.valueOf(value, 0, value.length));
  }
1047667
public void writeExternal(PofWriter writer)
            throws IOException {
        writer.writeObject(0, value);
        writer.writeBoolean(1, fReturnOld);
    }
915768
@Override
  public void writeAs(String uri, Object content)
    throws ResourceNotFoundException, ForbiddenUserException,
    FailedRequestException {
    writeAs(uri, null, content, null);
  }
521790
protected void writeContent(String requestedPath, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ResourceNotFoundException {

		// Send gzipped resource if user agent supports it.
		int idx = requestedPath.indexOf(BundleRenderer.GZIP_PATH_PREFIX);
		if (idx != -1) {

			requestedPath = JawrConstant.URL_SEPARATOR
					+ requestedPath.substring(idx + BundleRenderer.GZIP_PATH_PREFIX.length(), requestedPath.length());
			if (isValidRequestedPath(requestedPath)) {
				response.setHeader(CONTENT_ENCODING, GZIP);
				bundlesHandler.streamBundleTo(requestedPath, response.getOutputStream());
			} else {
				throw new ResourceNotFoundException(requestedPath);
			}

		} else {

			// In debug mode, we take in account the image generated from a
			// StreamGenerator like classpath Image generator
			// The following code will rewrite the URL path for the generated
			// images,
			// because in debug mode, we are retrieving the CSS resources
			// directly from the webapp
			// and if the CSS contains generated images, we should rewrite the
			// URL.
			BinaryResourcesHandler imgRsHandler = (BinaryResourcesHandler) servletContext
					.getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE);
			if (imgRsHandler != null && this.jawrConfig.isDebugModeOn() && resourceType.equals(JawrConstant.CSS_TYPE)) {

				handleGeneratedCssInDebugMode(requestedPath, request, response, imgRsHandler);
			} else {

				if (isValidRequestedPath(requestedPath)) {
					Writer out = response.getWriter();
					bundlesHandler.writeBundleTo(requestedPath, out);
				} else {
					throw new ResourceNotFoundException(requestedPath);
				}
			}
		}
	}
942822
private void writeObject(ObjectOutputStream out) throws IOException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "writeObject : " + this);

        throw new NotSerializableException("This entity manager is not serializable");
    }