Skip to content

Cloned from CL 753687051 by 'g4 patch'. #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions jre_emul/Classes/com/google/j2objc/util/PropertiesXmlLoader.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@

package java.nio;

import dalvik.annotation.compat.UnsupportedAppUsage;
import static libcore.io.OsConstants.O_ACCMODE;
import static libcore.io.OsConstants.O_RDONLY;
import static libcore.io.OsConstants.O_WRONLY;

import com.google.j2objc.LibraryNotLinkedError;
import java.io.Closeable;
import dalvik.annotation.compat.UnsupportedAppUsage;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Set;

import sun.misc.Cleaner;
import sun.nio.ch.DirectBuffer;
import sun.nio.ch.FileChannelImpl;

import static libcore.io.OsConstants.O_ACCMODE;
import static libcore.io.OsConstants.O_APPEND;
import static libcore.io.OsConstants.O_RDONLY;
import static libcore.io.OsConstants.O_WRONLY;

/**
* @hide internal use only
*/
Expand Down Expand Up @@ -64,43 +55,12 @@ public static FileDescriptor getFD(FileChannel fc) {
}
*/

/**
* Helps bridge between io and nio.
*/
public static FileChannel newFileChannel(Closeable ioObject, FileDescriptor fd, int mode) {
ChannelFactory factory = ChannelFactory.INSTANCE;
if (factory == null) {
throw new LibraryNotLinkedError("Channel support", "jre_channels",
"JavaNioChannelFactoryImpl");
}
return factory.newFileChannel(ioObject, fd, mode);
}

public static FileChannel newFileChannelSafe(Object stream, FileDescriptor fd, int mode) {
ChannelFactory factory = ChannelFactory.INSTANCE;
if (factory != null) {
return factory.newFileChannel(stream, fd, mode);
} else {
return null;
}
public FileChannel newFileChannel(Object ioObject, FileDescriptor fd, int mode) {
boolean readable = (mode & O_ACCMODE) != O_WRONLY;
boolean writable = (mode & O_ACCMODE) != O_RDONLY;
return FileChannelImpl.open(fd, null, readable, writable, ioObject);
}

static interface ChannelFactory {
FileChannel newFileChannel(Object stream, FileDescriptor fd, int mode);

static final ChannelFactory INSTANCE = getChannelFactory();
}

// Native implementation avoids the use of Class.forName(). This code might end up invoked from
// within the internals of Class.forName(), and re-invoking it causes deadlock.
private static native ChannelFactory getChannelFactory() /*-[
Class cls = NSClassFromString(@"JavaNioChannelFactoryImpl");
if (cls) {
return AUTORELEASE([[cls alloc] init]);
}
return nil;
]-*/;

/**
* Exposes the array backing a non-direct ByteBuffer, even if the ByteBuffer is read-only.
* Normally, attempting to access the array backing a read-only buffer throws.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,15 @@

package java.util;

import com.google.j2objc.LibraryNotLinkedError;
import com.google.j2objc.util.XmlLoader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;

// Android-removed: Dead native2ascii links.
// These links are also gone in OpenJDK 9.
Expand Down Expand Up @@ -910,21 +903,16 @@ private void store0(BufferedWriter bw, String comments, boolean escUnicode)
*/
public synchronized void loadFromXML(InputStream in)
throws IOException, InvalidPropertiesFormatException {
XmlLoader loader = getXmlLoader();
if (loader == null) {
throw new LibraryNotLinkedError(
"XML support", "jre_xml", "ComGoogleJ2objcUtilPropertiesXmlLoader");
}
loader.load(this, in);
}

private static XmlLoader getXmlLoader() {
try {
Class<?> loaderClass = Class.forName("com.google.j2objc.util.PropertiesXmlLoader");
return (XmlLoader) loaderClass.newInstance();
} catch (Exception e) {
return null;
}
// Android-changed: Keep OpenJDK7u40's XmlUtils.
// XmlSupport's system property based XmlPropertiesProvider
// selection does not make sense on Android and has too many
// dependencies on classes that are not available on Android.
//
// Objects.requireNonNull(in);
// PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
// handler.load(this, in);
XMLUtils.load(this, Objects.requireNonNull(in));
in.close();
}

/**
Expand Down Expand Up @@ -994,72 +982,23 @@ public void storeToXML(OutputStream os, String comment)
*/
public void storeToXML(OutputStream os, String comment, String encoding)
throws IOException {
if (os == null) {
throw new NullPointerException("os == null");
} else if (encoding == null) {
throw new NullPointerException("encoding == null");
}

// Android-changed: Keep OpenJDK7u40's XmlUtils.
// XmlSupport's system property based XmlPropertiesProvider
// selection does not make sense on Android and has too many
// dependencies on classes that are not available on Android.
/*
* We can write to XML file using encoding parameter but note that some
* aliases for encodings are not supported by the XML parser. Thus we
* have to know canonical name for encoding used to store data in XML
* since the XML parser must recognize encoding name used to store data.
*/
Objects.requireNonNull(os);
Objects.requireNonNull(encoding);

String encodingCanonicalName;
try {
encodingCanonicalName = Charset.forName(encoding).name();
} catch (IllegalCharsetNameException e) {
System.out.println("Warning: encoding name " + encoding
+ " is illegal, using UTF-8 as default encoding");
encodingCanonicalName = "UTF-8";
} catch (UnsupportedCharsetException e) {
System.out.println("Warning: encoding " + encoding
+ " is not supported, using UTF-8 as default encoding");
encodingCanonicalName = "UTF-8";
}

PrintStream printStream = new PrintStream(os, false,
encodingCanonicalName);

printStream.print("<?xml version=\"1.0\" encoding=\"");
printStream.print(encodingCanonicalName);
printStream.println("\"?>");

printStream.print("<!DOCTYPE properties SYSTEM \"");
printStream.print(PROP_DTD_NAME);
printStream.println("\">");

printStream.println("<properties>");

if (comment != null) {
printStream.print("<comment>");
printStream.print(substitutePredefinedEntries(comment));
printStream.println("</comment>");
Charset charset = Charset.forName(encoding);
storeToXML(os, comment, charset);
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
throw new UnsupportedEncodingException(encoding);
}

for (Map.Entry<Object, Object> entry : entrySet()) {
String keyValue = (String) entry.getKey();
String entryValue = (String) entry.getValue();
printStream.print("<entry key=\"");
printStream.print(substitutePredefinedEntries(keyValue));
printStream.print("\">");
printStream.print(substitutePredefinedEntries(entryValue));
printStream.println("</entry>");
}
printStream.println("</properties>");
printStream.flush();
}

private String substitutePredefinedEntries(String s) {
// substitution for predefined character entities to use them safely in XML.
s = s.replaceAll("&", "&amp;");
s = s.replaceAll("<", "&lt;");
s = s.replaceAll(">", "&gt;");
s = s.replaceAll("'", "&apos;");
s = s.replaceAll("\"", "&quot;");
return s;
*/
XMLUtils.save(this, Objects.requireNonNull(os), comment,
Objects.requireNonNull(encoding));
}

/**
Expand Down
Loading