當前位置: 首頁>>代碼示例>>Java>>正文


Java IO.write方法代碼示例

本文整理匯總了Java中io.advantageous.boon.core.IO.write方法的典型用法代碼示例。如果您正苦於以下問題:Java IO.write方法的具體用法?Java IO.write怎麽用?Java IO.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.advantageous.boon.core.IO的用法示例。


在下文中一共展示了IO.write方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeValue

import io.advantageous.boon.core.IO; //導入方法依賴的package包/類
@Override
public void writeValue( File dest, Object value ) {
    IO.write( Paths.get(dest.toString()), serializerFactory.create().serialize(value).toString());
}
 
開發者ID:advantageous,項目名稱:boon,代碼行數:5,代碼來源:ObjectMapperImpl.java

示例2: part9Options

import io.advantageous.boon.core.IO; //導入方法依賴的package包/類
public static void part9Options() throws Exception {

        puts ("\n\n\n", "\npart9Options");


        JsonParserFactory jsonParserFactory = new JsonParserFactory()
                .useFieldsFirst().useFieldsOnly().usePropertiesFirst().usePropertyOnly() //one of these
                .lax() //allow loose parsing of JSON like JSON Smart
                .strict() //opposite of lax
                .setCharset( StandardCharsets.UTF_8 ) //Set the standard charset, defaults to UTF_8
                .setChop( true ) //chops up buffer overlay buffer (more discussion of this later)
                .setLazyChop( true ) //similar to chop but only does it after map.get
                ;

        JsonSerializerFactory jsonSerializerFactory = new JsonSerializerFactory()
                .useFieldsFirst().useFieldsOnly().usePropertiesFirst().usePropertyOnly() //one of these
                //.addPropertySerializer(  )  customize property output
                //.addTypeSerializer(  )      customize type output
                .useJsonFormatForDates() //use json dates
                //.addFilter(  )   add a property filter to exclude properties
                .includeEmpty().includeNulls().includeDefaultValues() //override defaults
                .handleComplexBackReference() //uses identity map to track complex back reference and avoid them
                .setHandleSimpleBackReference( true ) //looks for simple back reference for parent
                .setCacheInstances( true ) //turns on caching for immutable objects
                ;



        final User diana = BeanUtils.copy( user );
        final User rick = BeanUtils.copy( user );
        diana.getName().setFirst( "Diana" );
        diana.setGender( User.Gender.FEMALE );
        rick.getName().setFirst( "Rick" );
        diana.setBirthDate( Dates.getUSDate( 8, 21, 1984 ) );
        List<User> users = Lists.list(  rick, diana );

        //You can use parser and serializer directly.
        final JsonParserAndMapper jsonParserAndMapper = jsonParserFactory.create();
        final JsonSerializer jsonSerializer = jsonSerializerFactory.create();

        File file = File.createTempFile( "userList", ".json" );
        String jsonString = jsonSerializer.serialize( users ).toString();

        puts( "JSON STRING", jsonString );

        IO.write( file.toString(), jsonString);
        List<User> users2 = jsonParserAndMapper.parseListFromFile( User.class, file.toString() );

        //Or you can pass them to the ObjectMapper interface you know and love, just pass the factories to it.
        ObjectMapper mapper = JsonFactory.create( jsonParserFactory, jsonSerializerFactory );


        mapper.writeValue( file, users  );
        List<User> userList = mapper.readValue( file, List.class, User.class  );
        puts (userList);
        puts ( mapper.writeValueAsString( userList ) );

        puts (userList);
        puts (users);
        boolean ok = userList.toString().equals ( users.toString() ) || die ( userList.toString() );



    }
 
開發者ID:advantageous,項目名稱:boon,代碼行數:65,代碼來源:JsonTutorial.java

示例3: main

import io.advantageous.boon.core.IO; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {


        File file = File.createTempFile("foo", "json");

        final JsonParserAndMapper jsonMapper =
                new JsonParserFactory()
                        .createFastObjectMapperParser();

        final JsonSerializer jsonSerializer = new JsonSerializerFactory()
                .create();

        final Sales salesOut = new Sales(1, "foo");
        final String json = jsonSerializer.serialize(salesOut).toString();

        puts(json);


        IO.write(file.toPath(), json);

        final String jsonIn = IO.read(file);


        puts("OUT", salesOut, jsonIn);





        final Sales salesIn = jsonMapper.parse(Sales.class, jsonIn);

        puts("OUT", salesIn, salesOut);


        assertEquals(salesOut, salesIn);



    }
 
開發者ID:advantageous,項目名稱:boon,代碼行數:40,代碼來源:JsonWorkingWithNonSerializableObjects.java

示例4: write

import io.advantageous.boon.core.IO; //導入方法依賴的package包/類
private void write(List<EndpointDefinition> fooServices) throws Exception {
    JsonSerializer jsonSerializer = new JsonSerializerFactory().create();
    String json = jsonSerializer.serialize(fooServices).toString();

    File outputFile = new File(dir, "fooBar.json");

    IO.write(outputFile.toPath(), json);

}
 
開發者ID:advantageous,項目名稱:qbit,代碼行數:10,代碼來源:ServiceDiscoveryWithFileSystemTest.java


注:本文中的io.advantageous.boon.core.IO.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。