77import java .io .*;
88import java .lang .ref .SoftReference ;
99import java .net .URL ;
10+ import java .nio .file .Files ;
11+ import java .nio .file .Path ;
1012import java .util .List ;
1113import java .util .Locale ;
1214
@@ -703,6 +705,32 @@ public PropertyNameMatcher constructCINameMatcher(List<Named> matches, boolean a
703705 public abstract JsonParser createParser (ObjectReadContext readCtxt ,
704706 File f ) throws JacksonException ;
705707
708+ /**
709+ * Method for constructing parser instance to decode
710+ * contents of specified path.
711+ *<p>
712+ * Encoding is auto-detected from contents according to JSON
713+ * specification recommended mechanism. Json specification
714+ * supports only UTF-8, UTF-16 and UTF-32 as valid encodings,
715+ * so auto-detection implemented only for this charsets.
716+ * For other charsets use {@link #createParser(java.io.Reader)}.
717+ *<p>
718+ * Underlying input stream (needed for reading contents)
719+ * will be <b>owned</b> (and managed, i.e. closed as need be) by
720+ * the parser, since caller has no access to it.
721+ *
722+ * @param readCtxt Object read context to use
723+ * @param p Path that contains content to parse
724+ *
725+ * @return Parser constructed
726+ *
727+ * @throws JacksonException If parser construction or initialization fails
728+ *
729+ * @since 3.0
730+ */
731+ public abstract JsonParser createParser (ObjectReadContext readCtxt ,
732+ Path p ) throws JacksonException ;
733+
706734 /**
707735 * Method for constructing JSON parser instance to decode
708736 * contents of resource reference by given URL.
@@ -1131,6 +1159,30 @@ public abstract JsonGenerator createGenerator(ObjectWriteContext writeCtxt, File
11311159 JsonEncoding enc )
11321160 throws JacksonException ;
11331161
1162+ /**
1163+ * Method for constructing generator that writes contents
1164+ * to specified path, overwriting contents it might have (or creating
1165+ * it if such path does not yet exist).
1166+ *<p>
1167+ * Underlying stream <b>is owned</b> by the generator constructed,
1168+ * i.e. generator will handle closing of path when
1169+ * {@link JsonGenerator#close} is called.
1170+ *
1171+ * @param writeCtxt Object-binding context where applicable; used for providing contextual
1172+ * configuration
1173+ * @param p Path to write contents to
1174+ * @param enc Character set encoding to use (usually {@link JsonEncoding#UTF8})
1175+ *
1176+ * @return Generator constructed
1177+ *
1178+ * @throws JacksonException If generator construction or initialization fails
1179+ *
1180+ * @since 3.0
1181+ */
1182+ public abstract JsonGenerator createGenerator (ObjectWriteContext writeCtxt , Path p ,
1183+ JsonEncoding enc )
1184+ throws JacksonException ;
1185+
11341186 /**
11351187 * Method for constructing generator that writes content into specified {@link DataOutput},
11361188 * using UTF-8 encoding (with formats where encoding is user-configurable).
@@ -1329,6 +1381,15 @@ protected InputStream _fileInputStream(File f) throws JacksonException
13291381 }
13301382 }
13311383
1384+ protected InputStream _pathInputStream (Path p ) throws JacksonException
1385+ {
1386+ try {
1387+ return Files .newInputStream (p );
1388+ } catch (IOException e ) {
1389+ throw _wrapIOFailure (e );
1390+ }
1391+ }
1392+
13321393 protected OutputStream _fileOutputStream (File f ) throws JacksonException
13331394 {
13341395 try {
@@ -1338,6 +1399,15 @@ protected OutputStream _fileOutputStream(File f) throws JacksonException
13381399 }
13391400 }
13401401
1402+ protected OutputStream _pathOutputStream (Path p ) throws JacksonException
1403+ {
1404+ try {
1405+ return Files .newOutputStream (p );
1406+ } catch (IOException e ) {
1407+ throw _wrapIOFailure (e );
1408+ }
1409+ }
1410+
13411411 protected JacksonException _wrapIOFailure (IOException e ) {
13421412 return WrappedIOException .construct (e , this );
13431413 }
0 commit comments