Source:
<code>private ContentItem generateContentFile( ContentItem item, Path contentDirectory, String storeReference) throws IOException { LOGGER.trace("ENTERING: generateContentFile"); if (!contentDirectory.toFile().exists()) { Files.createDirectories(contentDirectory); } long copySize; Path contentItemPath = Paths.get(contentDirectory.toAbsolutePath().toString(), item.getFilename()); ByteSource byteSource; if (storeReference != null) { copySize = item.getSize(); String encryptedReference = crypter.encrypt(storeReference); Files.write( Paths.get(contentItemPath.toString() + "." + REF_EXT), <START> encryptedReference.getBytes(Charset.defaultCharset())); <END> byteSource = new ByteSource() { @Override public InputStream openStream() throws IOException { return new URL(storeReference).openStream(); } }; } else { try (InputStream plainInputStream = item.getInputStream(); InputStream encryptedInputStream = crypter.encrypt(plainInputStream)) { copySize = Files.copy(encryptedInputStream, contentItemPath); } byteSource = com.google.common.io.Files.asByteSource(contentItemPath.toFile()); if (copySize < item.getSize() && LOGGER.isWarnEnabled()) { LOGGER.warn( "Created content item encrypted size is not greater than plain size {}.{}" + "Verify filesystem and/or network integrity.", item.getId(), copySize, item.getSize(), System.lineSeparator()); } } ContentItemImpl contentItem = new ContentItemImpl( item.getId(), item.getQualifier(), byteSource, item.getMimeType().toString(), contentItemPath.getFileName().toString(), copySize, item.getMetacard()); LOGGER.trace("EXITING: generateContentFile"); return contentItem; }</code><technical_language>I want rely default charset here. This is depending OS, is UTF-8 place</technical_language>

Target:
private ContentItem generateContentFile( ContentItem item, Path contentDirectory, String storeReference) throws IOException { LOGGER.trace("ENTERING: generateContentFile"); if (!contentDirectory.toFile().exists()) { Files.createDirectories(contentDirectory); } long copySize; Path contentItemPath = Paths.get(contentDirectory.toAbsolutePath().toString(), item.getFilename()); ByteSource byteSource; if (storeReference != null) { copySize = item.getSize(); String encryptedReference = crypter.encrypt(storeReference); Files.write( Paths.get(contentItemPath.toString() + "." + REF_EXT), encryptedReference.getBytes(Charset.forName("UTF-8"))); byteSource = new ByteSource() { @Override public InputStream openStream() throws IOException { return new URL(storeReference).openStream(); } }; } else { try (InputStream plainInputStream = item.getInputStream(); InputStream encryptedInputStream = crypter.encrypt(plainInputStream)) { copySize = Files.copy(encryptedInputStream, contentItemPath); } byteSource = com.google.common.io.Files.asByteSource(contentItemPath.toFile()); if (copySize < item.getSize() && LOGGER.isWarnEnabled()) { LOGGER.warn( "Created content item encrypted size is not greater than plain size {}.{}" + "Verify filesystem and/or network integrity.", item.getId(), copySize, item.getSize(), System.lineSeparator()); } } ContentItemImpl contentItem = new ContentItemImpl( item.getId(), item.getQualifier(), byteSource, item.getMimeType().toString(), contentItemPath.getFileName().toString(), copySize, item.getMetacard()); LOGGER.trace("EXITING: generateContentFile"); return contentItem; }