<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vanio Meurer - Java Programmer</title>
	<atom:link href="http://www.vaniomeurer.com.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vaniomeurer.com.br</link>
	<description>prazer, vaninh0.</description>
	<lastBuildDate>Wed, 29 Feb 2012 03:46:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Software de Gerenciamento de Mesas de Poker</title>
		<link>http://www.vaniomeurer.com.br/2012/02/29/software-de-gerenciamento-de-mesas-de-poker/</link>
		<comments>http://www.vaniomeurer.com.br/2012/02/29/software-de-gerenciamento-de-mesas-de-poker/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 03:31:26 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[tournamentpokermanager]]></category>
		<category><![CDATA[tpm]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=285</guid>
		<description><![CDATA[Post onde divulgo o projeto de nome TournamentPokerManager, ou TPM, de minha autoria. Deixo o link para download tanto do projeto como do source. O código fonte está liberado a qualquer pessoa que esteja interessada em dar continuidade ao projeto.]]></description>
			<content:encoded><![CDATA[<p>Opa, só vai? Beleza então.<br />
Hoje estava jogando um campeonato live de poker com uns amigos, e um deles me pediu o software que fiz para utilizar no <a title="1 BN Open Poker" href="http://www.vaniomeurer.com.br/bnop/" target="_blank">1º BN Open Poker</a>.<br />
E por isso estamos aqui, eu tinha esquecido de disponibilizar aqui o source do projeto, e farei nesse post.</p>
<p>Eu chamei o software de Tornament Poker Manager (uau, que nome em) e apelidei de TPM. Tive somente alguns dias para o desenvolvimento, então não da pra esperar grande coisa (ahh!)<br />
Dividi ele em duas partes, a view e o core. Logicamente deixei a view com elementos da GUI e a core com as regras de negocio.</p>
<p><strong>View</strong></p>
<p>A GUI ficou bem simples, utilizei somente elementos básicos de Swing.</p>
<p><strong>Core</strong></p>
<p>Na core eu quis utilizar o design pattern Command, então para todas as funcionalidades foi criado um Command, tentei pelo menos.. como o tempo foi curto, não lembro se ficou 100%.<br />
Pensei em fazer um tipo de mecanismo de log/backup que gravasse qualquer funcionalidade que fosse executada, sendo possível uma restauração caso acontecesse algo durante o torneio. Utilizei a serialização para tal (criando uma classe que contem um Map com o que queria gravar), creio que não foi uma excelente idéia. Talvez um banco de dados fosse uma solução melhor para resolver algum possível problema. Que seja, essa versão 0.2 está assim e assim será aqui divulgado <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>O que o software faz&#8230;?</strong></p>
<ul>
<li>Cadastra Jogadores.</li>
<li>Sorteio de lugares nas Mesas.</li>
<li>Controle de Rebuy.</li>
<li>Reorganização de mesas.</li>
<li>Backup automático.</li>
</ul>
<p>Bom, acho que é isso, baixe o source: <a title="Download do código fonte do TPM" href="http://www.vaniomeurer.com.br/wp-content/uploads/2012/02/TPM-v0.2.source.zip">TournamentPokerManager-v0.2.source</a><br />
Ou o executável jar aqui: <a title="Download do executável do TPM" href="http://www.vaniomeurer.com.br/wp-content/uploads/2012/02/TPM-v0.2.zip">TournamentPokerManager-v0.2</a></p>
<p>Toda alteração no projeto esta liberada da minha parte, mas seria legal divulgar aqui, só pra matar minha curiosidade. hehe<br />
Qualquer dúvida, estamos ai.<br />
Abraço, Vânio Meurer (vaninh0).</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2012/02/29/software-de-gerenciamento-de-mesas-de-poker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testando o Apache Pivot</title>
		<link>http://www.vaniomeurer.com.br/2012/02/25/testando-o-apache-pivot/</link>
		<comments>http://www.vaniomeurer.com.br/2012/02/25/testando-o-apache-pivot/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 12:46:10 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Apache Pivot]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Java SE]]></category>
		<category><![CDATA[apache pivot]]></category>
		<category><![CDATA[GSON]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=277</guid>
		<description><![CDATA[Nesse post mostro uma aplicação que fiz para testar o Apache Pivot.]]></description>
			<content:encoded><![CDATA[<p>Opa, só vai?<br />
Então, depois de muito tempo desaparecido, estou aqui novamente.<br />
A tecnologia que estou abordando hoje era um post programado para no mínimo a um ano atrás, porem com a correria do dia a dia fui acabando deixando de lado.<br />
Bom, chega de lenga lenga&#8230;</p>
<p><strong>O que é o Apache Pivot?</strong><br />
Segundo a própria Apache no site oficial no Pivot:<br />
<em>&#8220;Apache Pivot ™ é uma plataforma open-source para a criação de aplicativos instaláveis ​​Internet (AII). Ele combina o aumento de produtividade e características de utilização de um kit de ferramentas de interface de usuário moderna com a robustez da plataforma Java.&#8221;</em> (Traduzido pelo maravilhoso google translator).<br />
Segundo a minha experiência com a ferramenta:<br />
<em>&#8220;É um projeto que te possibilita fazer ferramentas tanto online (applet..) quanto desktop, mas com uma aparência e efeitos bem maneirinhos.&#8221;</em><br />
Bom mas só isso? É só um skin então?<br />
Nã, pera lá. Ele tem diversas &#8220;coisinhas&#8221; que facilitam a vida, principalmente para usar nos componentes gráficos deles. Dentre algumas que eu lembro são, uma parte de Collections toda própria para o Pivot e uma parte toda escalonada de serialização, com a parte de JSON toda pronta e algumas classes que te facilitam para utilizar REST.</p>
<p><strong>Minha aplicação exemplo</strong><br />
A minha aplicação exemplo se encontra nesse endereço:<br />
<a title="Aplicacao Exemplo Pivot" href="../pivot/" target="_blank">http://www.vaniomeurer.com.br/pivot/</a></p>
<p><strong>O que eu usei nessa aplicação?</strong></p>
<ol start="1">
<li>Apache Pivot</li>
<li>GSON</li>
<li>Google App Engine</li>
<li>REST</li>
</ol>
<p>Porque tudo isso?<br />
Com o Pivot eu fiz a parte gráfica. Deixei uma aplicação REST rodando no Google App Engine. E o GSON? Pra que utilizá-lo se eu mesmo disse que o Pivot já traz as funcionalidades para trabalhar com JSON? Simples e direto, tive problemas com o java.util.Date ;/</p>
<p><strong>Finalizando&#8230; o que eu achei do Apache Pivot?</strong></p>
<p>Bom, eu achei ele muito bonito. Porem muito difícil de programar.<br />
Eu sei que o post ficou muito vago, eu tinha a intenção de mostrar como programar no Pivot, e todo o fonte do projeto. Mas to numa maquina nova e o projeto não está aqui. Pretendo no futuro mostrar mais detalhes sobre o projeto.</p>
<p>Abraço, Vânio Meurer. (Vaninh0)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2012/02/25/testando-o-apache-pivot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problemas&#8230;</title>
		<link>http://www.vaniomeurer.com.br/2012/02/23/problemas/</link>
		<comments>http://www.vaniomeurer.com.br/2012/02/23/problemas/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 01:50:17 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Sem categoria]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=272</guid>
		<description><![CDATA[Galerinha, devido a ataques ao blog, tive que reinstalar o wordpress e perdi meu teminha bonitinho, snif snif. Bom, to tentando deixar tudo nos conformes aqui, desculpem os transtornos. Abraço. Vanio Meurer.]]></description>
			<content:encoded><![CDATA[<p>Galerinha, devido a ataques ao blog, tive que reinstalar o wordpress e perdi meu teminha bonitinho, snif snif.<br />
Bom, to tentando deixar tudo nos conformes aqui, desculpem os transtornos.</p>
<p>Abraço.<br />
Vanio Meurer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2012/02/23/problemas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objectify, uma ótima pedida para o Google App Engine</title>
		<link>http://www.vaniomeurer.com.br/2011/01/19/objectify-uma-otima-pedida-para-o-google-app-engine/</link>
		<comments>http://www.vaniomeurer.com.br/2011/01/19/objectify-uma-otima-pedida-para-o-google-app-engine/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 13:34:29 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[objectify]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=264</guid>
		<description><![CDATA[Sugerindo o uso do Objectify quando estiver utilizando o Google App Engine Java. Também uma dica para inserir na sua entidade que vai te poupar algum trabalho.]]></description>
			<content:encoded><![CDATA[<p>Boa tarde Queridos Leitores.<br />
Eu sei que faz tempo, mas estou aqui postando depois de tantos meses.<br />
Estou vivo, obrigado pela preocupação (tudo bem&#8230; ninguém perguntou nada, mas eu gosto de me sentir lembrado as vezes).</p>
<p>Como ninguém sabe, corrigindo, alguns sabem&#8230; A programação agora passou a ser apenas um Hobby.<br />
Não estou mais trabalhando com programação, tenho saudades do meu tempo de analista, snif snif.</p>
<p>Mas vamos ao assunto, afinal essa budega não foi feita para falar da minha vida pessoal e ela tão pouco interessa a você, eu sei <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A tecnologia que venho apresentar e sugerir seu uso é o Objectify. Também vou deixar uma dica de um código que me facilitou bastante as coisas.</p>
<p>Mas para que serve? Da onde veio? Porque usar isso?</p>
<p>Então, vamos a mais história pessoal (hoje to me sentindo um blogueiro.. haha).<br />
A um tempo venho projetando um sistema para uns controles pessoais, queria que fosse na web e ai surgiu um problema chato, CUSTOS R$$$ (falando nisso, já deu uma olhada nos anúncios? Grato)!<br />
Foi querendo driblar esses CUSTOS que eu decidi utilizar o <a href="http://code.google.com/intl/pt-BR/appengine/docs/java/overview.html">Google App Engine/J</a> (GAE), que me disponibilizou um ambiente free.<br />
Só que, o GAE não utiliza base de dados com a arquitetura SGBD a qual a maioria de nós estamos acostumados a trabalhar, ele utiliza uma arquitetura chamada <a href="http://pt.wikipedia.org/wiki/BigTable">BigTable</a>, fazendo com que os frameworks de persistência sejam um pouco diferentes.</p>
<p>Ai você vai falar: Ah, mas você pode utilizar JPA com o GAE.<br />
E eu respondo: Pelo meu uso, pelas minhas pesquisas, eu digo que o JPA no GAE é uma dor de cabeça do cão. As coisas tendem a não funcionar como o esperado.</p>
<p>E nessas pesquisas eu encontrei o Objectify, um framework de persistência de muito fácil instalação e bem simples de ser utilizado.</p>
<p>Como Instalar? Como utilizar?<br />
Você pode encontrar todas essas informações no site oficial do projeto:<br />
<a href="http://code.google.com/p/objectify-appengine/">http://code.google.com/p/objectify-appengine/</a></p>
<p>E caso surgir alguma dúvida, pergunte aqui pra podermos trocar algumas experiências.</p>
<p>Então, quando você começar a utilizar o Objectify você vai ver que as relações entre as tabelas aqui não podem ser mapeadas assim:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Motor <span style="color: #009900;">&#123;</span>
...
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Carro <span style="color: #009900;">&#123;</span>
...
<span style="color: #000000; font-weight: bold;">private</span> Motor motor<span style="color: #339933;">;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Você precisa utilizar uma Key, no exemplo deveríamos utilizar Key<Motor> motor.<br />
A classe Carro agora ficaria assim:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Carro <span style="color: #009900;">&#123;</span>
...
<span style="color: #000000; font-weight: bold;">private</span> Key<span style="color: #339933;">&lt;</span>Motor<span style="color: #339933;">&gt;</span> motor<span style="color: #339933;">;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Com essa key você consegue recuperar a real instancia de Motor utilizando o método get(class, id).<br />
Mas fica um tanto chato ter que fazer isso a toda hora. Então eu pensei e comecei a fazer isso nas minhas classes:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Carro <span style="color: #009900;">&#123;</span>
...
<span style="color: #000000; font-weight: bold;">private</span> Key<span style="color: #339933;">&lt;</span>Motor<span style="color: #339933;">&gt;</span> motorId<span style="color: #339933;">;</span>
@Transiant <span style="color: #000000; font-weight: bold;">private</span> Motor motor<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> Motor getMotor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">motor</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> motorId <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Motor motor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Motor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		motor.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>motorId.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">motor</span> <span style="color: #339933;">=</span> MotorDAO.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>motor.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, motor.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">motor</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMotor<span style="color: #009900;">&#40;</span>Motor motor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">motor</span> <span style="color: #339933;">=</span> motor<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>motor <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> motor.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">motorId</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Key<span style="color: #339933;">&lt;</span>Motor<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>Motor.<span style="color: #000000; font-weight: bold;">class</span>,
				motor.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>E até agora tudo ta funcionando belezinha! Posso fazer referencia diretamente nas EL do JSF e zaz.</p>
<p>Então essa seria minha dica de hoje.</p>
<p>PS: Como minha aplicação ainda não esta em produção, tão pouco ta fazendo coisas complexas, pode ser que esse código passe a não funcionar, mas nada que um jeitinho brasileiro não resolva <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>É isso pessoal, espero que seja útil a você.<br />
Abraço,<br />
Vanio Meurer (vaninhO).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2011/01/19/objectify-uma-otima-pedida-para-o-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Como acessar sites (URL) com java</title>
		<link>http://www.vaniomeurer.com.br/2010/03/14/como-acessar-sites-url-com-java/</link>
		<comments>http://www.vaniomeurer.com.br/2010/03/14/como-acessar-sites-url-com-java/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 13:12:52 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[java.net.HTTPURLConnection]]></category>
		<category><![CDATA[java.net.URL]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=253</guid>
		<description><![CDATA[Nesse post escrevo sobre como você pode acessar a sites da internet usando somente Java. Utilizamos para tal as classes do pacote java.net, URL e HTTPURLConnection.]]></description>
			<content:encoded><![CDATA[<p>Boa tarde, estou aqui num raro momento de ócio e resolvi postar algo simples, que é acessar algum site com o Java e ler seu código HTML.</p>
<p>Para tal utilizaremos as classes URL e HTTPUrlConnection do pacote java.net.</p>
<p>Começamos criando uma instancia de URL, passando ao seu construtor uma String. Como visto no exemplo abaixo essa String é a própria URL que desejamos acessar.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.vaniomeurer.com.br&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Detalhe que esse construtor pode lançar uma exception chamada MalformedURLException e essa mesma é uma exception verificada, então precisamos tratá-la no código, ficando assim nosso código:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
   java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.vaniomeurer.com.br&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">net</span>.<span style="color: #003399;">MalformedURLException</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Erro ao criar URL. Formato inválido.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Existem alguns outros construtores para a classe java.net.URL, porem esse é o mais comum.</p>
<p>Depois que já temos a nossa URL, precisamos acessá-la. O Java já traz uma classe que nos abstrai muitos detalhes de baixo nível do protocolo HTTP. A classe é a java.net.HTTPURLConnection e usamos como a seguir:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">java.<span style="color: #006633;">net</span>.<span style="color: #006633;">HTTPURLConnection</span> urlConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">net</span>.<span style="color: #006633;">HTTPURLConnection</span><span style="color: #009900;">&#41;</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Como o método retorna uma URLConnection abstrata, precisamos fazer o cast para nossa HTTPURLConnection, pois estamos tratando de uma transação HTTP.</p>
<p>Novamente precisamos tratar uma exception, nesse caso o método openConnection da URL pode retornar uma IOException, então modificando e juntando os códigos temos:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
   java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.vaniomeurer.com.br&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   java.<span style="color: #006633;">net</span>.<span style="color: #006633;">HTTPURLConnection</span> urlConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">net</span>.<span style="color: #006633;">HTTPURLConnection</span><span style="color: #009900;">&#41;</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">net</span>.<span style="color: #003399;">MalformedURLException</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Erro ao criar URL. Formato inválido.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">io</span>.<span style="color: #006633;">IOExcetpion</span> e2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Erro ao acessar URL.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sabendo que a classe MalformedURLException herda IOException poderíamos ter tratado somente a exception IOExceptin, mas deixei assim para que o erro fique mais especifico.</p>
<p>Tendo aberta a conexão precisamos pegar as informações, para isso abrimos a stream de input assim:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">java.<span style="color: #006633;">io</span>.<span style="color: #003399;">BufferedReader</span> in <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">ioInputStream</span><span style="color: #009900;">&#40;</span>urlConnection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Também temos disponível o stream de Output, que pode ser conseguido através do método getOutputStream.<br />
 Com o stream de entrada (input), basta percorrermos o stream para mostrarmos a página HTML.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> in.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Conforme fizemos, vamos ler linha por linha a página HTML e exibir na tela. Poderíamos ter usado qualquer outro leitor de streams.<br />
 Pronto, lemos uma página HTML utilizando Java. <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br />
 Precisamos agora fechar a conexão e os streams abertos.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">in.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
urlConnection.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>IMPORTANTE:</strong> precisamos sempre fechar os streams antes da conexão, caso contrario lançaríamos uma exception!</p>
<p>O código completo ficaria assim:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.vaniomeurer.exemplos</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.HTTPURLConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.MalformedURLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AcessarURL <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Não foi especificado nenhuma URL.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">// Fechando aplicação.</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Pegando a url passada como parametro.</span>
      <span style="color: #003399;">String</span> urlName <span style="color: #339933;">=</span> args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
         <span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>urlName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         HTTPURLConnection urlConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HTTPURLConnection<span style="color: #009900;">&#41;</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #003399;">BufferedReader</span> in <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>urlConnection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> in.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         in.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         urlConnection.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">MalformedURLException</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Erro ao criar URL. Formato inválido.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Erro ao acessar URL.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compilando e executando o comando &#8220;java br.com.vaniomeurer.exemplos.AcessarURL http://www.vaniomeurer.com.br&#8221; teríamos impresso o código HTML desse site. <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Espero que esse mini tutorial seja útil a alguém, como estou em uma máquina que não tem o JDK não pude compilar para testar, mas logo o faço e edito caso algo esteja errado.</p>
<p>Até, Vânio Meurer (vaninhO)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2010/03/14/como-acessar-sites-url-com-java/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>EasyFaces &#8211; Apresentação do projeto</title>
		<link>http://www.vaniomeurer.com.br/2009/11/30/easyfaces-apresentacao-do-projeto/</link>
		<comments>http://www.vaniomeurer.com.br/2009/11/30/easyfaces-apresentacao-do-projeto/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 01:29:22 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[EasyFaces]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[apresentação tcc]]></category>
		<category><![CDATA[componentes jsf]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=248</guid>
		<description><![CDATA[Post onde venho publicar a apresentação do projeto EasyFaces, disponibilizando o video e os slides da apresentação do TCC de Vânio Stang Meurer (eu) e Rafael da Cunha para defesa do grau de bacharel na UNISUL.]]></description>
			<content:encoded><![CDATA[<p>Bom dia povo,</p>
<p>a apresentação do projeto <a title="EasyFaces - Site do projeto" href="http://www.easyfaces.com.br" target="_blank">EasyFaces</a> como escrevi no <a title="EasyFaces - Pacote de componentes JSF brasileiro" href="http://www.vaniomeurer.com.br/2009/11/19/easyfaces-pacote-de-componentes-jsf-brasileiro/" target="_blank">post anterior</a> ocorreu no dia 23/11.<br />
 A mesma foi realizada para a defesa do nosso grau de Bacharel em Sistemas de Informação pela Universidade do Sul de Santa Catarina (UNISUL).<br />
 Fomos orientados pelo professor Edjandir Correa Costa (MSc.), nossa banca foi composta pelos Srs. Max Roberto Pereira (Dr.), Luiz Alfredo Soares Garcindo (Dr.) e Cássio Nandi Citadim.</p>
<p>Acho que a apresentação ficou bem legal, você pode conferir no video abaixo:</p>
<p>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7846142&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=7846142&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</p>
<p><a href="http://vimeo.com/7846142">EasyFaces &#8211; Pacote de Componentes JSF</a> from <a href="http://vimeo.com/easyfaces">EasyFaces</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Os slides tambem estão dispostos a seguir:</p>
<p><img style="visibility: hidden; width: 0px; height: 0px;" src="http://counters.gigya.com/wildfire/IMP/CXNID=2000002.0NXC/bT*xJmx*PTEyNTk2MzAyNTg5NzEmcHQ9MTI1OTYzMDQ5MzE4NyZwPTEwMTkxJmQ9c3NfZW1iZWQmZz*yJm89MGExOWQzYjllMzQwNGE4YjlkYTNlMDI4Y2VjM2RkNjcmb2Y9MA==.gif" border="0" alt="" width="0" height="0" /></p>
<div id="__ss_2585174" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="EasyFaces - Framework de Componentes JSF" href="http://www.slideshare.net/faelbn/easyfaces-framework-de-componentes-jsf">EasyFaces &#8211; Framework de Componentes JSF</a><br />
<object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tcc-apresentacao-091125150351-phpapp01&amp;stripped_title=easyfaces-framework-de-componentes-jsf" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tcc-apresentacao-091125150351-phpapp01&amp;stripped_title=easyfaces-framework-de-componentes-jsf" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/faelbn">Rafael da Cunha</a>.</div>
</div>
<p>Já recebemos alguns contatos pelo site, alguns parabenizando e outros reportando algum tipo de comportamento inesperado. Todos serão considerados e quando necessário corrigidos nas versões posteriores.</p>
<p>Vale ressaltar que é de suma importância que você de seu <a title="EasyFaces - Contato" href="http://www.easyfaces.com.br/contato/" target="_blank">feedback</a> sobre o projeto, para sabermos por onde seguir e facilitarmos a vida de mais alguns desenvolvedores (como nós) <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Não esquecendo também que a idéia é liberar o código fonte do projeto para que mais pessoas também possam ajudar no desenvolvimento e amadurecimento do projeto.</p>
<p>Acho que seria isso, agradeço pelas mensagens de apoio e com o decorrer do projeto venho postar as novidades por aqui.</p>
<p>Vânio Meurer (vaninh0)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2009/11/30/easyfaces-apresentacao-do-projeto/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>EasyFaces &#8211; Pacote de componentes JSF brasileiro</title>
		<link>http://www.vaniomeurer.com.br/2009/11/19/easyfaces-pacote-de-componentes-jsf-brasileiro/</link>
		<comments>http://www.vaniomeurer.com.br/2009/11/19/easyfaces-pacote-de-componentes-jsf-brasileiro/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 18:44:55 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[EasyFaces]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[jsf]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=242</guid>
		<description><![CDATA[Nesse post comento sobre o lançamento do EasyFaces, um pacote de componentes para JSF que eu em parceria com Rafael da Cunha criamos para nosso TCC.]]></description>
			<content:encoded><![CDATA[<p>É com imenso prazer que venho noticiar hoje o lançamento do EasyFaces, um pacote de componentes JSF. Esse projeto nasceu no meu TCC em parceria com <a title="Site de Rafael da Cunha" href="http://www.rafaeldacunha.com.br" target="_blank">Rafael da Cunha</a> e resolvemos publica-lo para uso de quem o acha-lo interessante <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Você pode conferir todo o conteúdo do EasyFaces no site <a title="Site do projeto EasyFaces" href="http://www.easyfaces.com.br" target="_blank">www.easyfaces.com.br</a>, lá você vai encontrar desde o download a demonstração “instantânea” de cada componente.</p>
<p>Visite e confira!</p>
<p>Ah&#8230; quase ia esquecendo, dia 23/11 estaremos apresentando nosso TCC, torçam por nós.</p>
<p>Vânio Meurer (vaninhO)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2009/11/19/easyfaces-pacote-de-componentes-jsf-brasileiro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Desenhando o Fantasminha do PacMan com Java 2D</title>
		<link>http://www.vaniomeurer.com.br/2009/11/10/desenhando-o-fantasminha-do-pacman-com-java-2d/</link>
		<comments>http://www.vaniomeurer.com.br/2009/11/10/desenhando-o-fantasminha-do-pacman-com-java-2d/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 13:59:21 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[fantasma]]></category>
		<category><![CDATA[java 2d]]></category>
		<category><![CDATA[jogos]]></category>
		<category><![CDATA[pac man]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=234</guid>
		<description><![CDATA[Visitando o site Ponto V (www.pontov.com.br) que é um site de desenvolvimento de jogos, surgiu um desafio de desenhar o fantasma do pac man utilizando apenas Java 2D, nesse posto demonstro como ficou meu código fonte.]]></description>
			<content:encoded><![CDATA[<p>Buenas,</p>
<p>estava lendo o novo portal desenvolvimento de jogos, o <a title="Ponto V" href="http://www.pontov.com.br" target="_blank">Ponto V</a>, que os colegas Vinicius Godoy Mendonça e Bruno Crivelari Sanches estão escrevendo e no post <a title="Pintando no Java 2D - Ponto V" href="http://www.pontov.com.br/site/index.php?option=com_content&amp;view=article&amp;id=97:pintando-no-java-2d&amp;catid=48:java2d&amp;Itemid=58" target="_blank">Pintando no Java 2D</a> surgiu um desafio de desenhar o fantasminha do PacMan com Java2D.</p>
<p>Abaixo minha solução do desafio, não fico muito bonitinho, mas ta ai o código fonte que criei.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Color</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.EventQueue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Graphics</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Graphics2D</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.geom.Ellipse2D</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.geom.QuadCurve2D</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.geom.Rectangle2D</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JFrame</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Pintando fantasminha do PacMan com Java 2D.
 * @author Vânio Meurer
 * @since 10/11/2009 11:38:12
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FantasmaPacMan <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">JFrame</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 8366583475473482894L<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> TAMANHO_X <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> TAMANHO_Y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> TAMANHO_X_PATA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> TAMANHO_Y_PATA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> DISTANCIA_X_PATA <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> RAIO_OLHO <span style="color: #339933;">=</span> <span style="color: #cc66cc;">13</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> RAIO_OLHO_CRISTALINO <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> DISTANCIA_X_OLHOS <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>RAIO_OLHO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> FantasmaPacMan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fantasminha Pac Man&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">setSize</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">setDefaultCloseOperation</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">JFrame</span>.<span style="color: #006633;">EXIT_ON_CLOSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">setLocationRelativeTo</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">final</span> FantasmaPacMan fpm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FantasmaPacMan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">EventQueue</span>.<span style="color: #006633;">invokeLater</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				fpm.<span style="color: #006633;">setVisible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> paint<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">paint</span><span style="color: #009900;">&#40;</span>g<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">Graphics2D</span> g2d <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics2D</span><span style="color: #009900;">&#41;</span> g.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">width</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		pintarFantasma<span style="color: #009900;">&#40;</span>g2d, <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		pintarFantasma<span style="color: #009900;">&#40;</span>g2d, <span style="color: #003399;">Color</span>.<span style="color: #006633;">MAGENTA</span>, <span style="color: #cc66cc;">85</span>, <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> pintarFantasma<span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics2D</span> g2d, <span style="color: #003399;">Color</span> color, <span style="color: #000066; font-weight: bold;">int</span> x, <span style="color: #000066; font-weight: bold;">int</span> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Ellipse2D.<span style="color: #006633;">Float</span></span><span style="color: #009900;">&#40;</span>x, y, TAMANHO_X, TAMANHO_Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Rectangle2D</span>.<span style="color: #003399;">Float</span><span style="color: #009900;">&#40;</span>x,y<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>,TAMANHO_X, TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> xBkp <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span>
&nbsp;
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">QuadCurve2D</span>.<span style="color: #003399;">Float</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #339933;">+</span>TAMANHO_Y, x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X_PATA<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #339933;">+</span>TAMANHO_Y_PATA, x<span style="color: #339933;">+</span>TAMANHO_X_PATA, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		x <span style="color: #339933;">=</span> x<span style="color: #339933;">+</span>TAMANHO_X_PATA<span style="color: #339933;">+</span>DISTANCIA_X_PATA<span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">QuadCurve2D</span>.<span style="color: #003399;">Float</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #339933;">+</span>TAMANHO_Y, x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X_PATA<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #339933;">+</span>TAMANHO_Y_PATA, x<span style="color: #339933;">+</span>TAMANHO_X_PATA, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		x <span style="color: #339933;">=</span> x<span style="color: #339933;">+</span>TAMANHO_X_PATA<span style="color: #339933;">+</span>DISTANCIA_X_PATA<span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">QuadCurve2D</span>.<span style="color: #003399;">Float</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #339933;">+</span>TAMANHO_Y, x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X_PATA<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #339933;">+</span>TAMANHO_Y_PATA, x<span style="color: #339933;">+</span>TAMANHO_X_PATA, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		x <span style="color: #339933;">=</span> x<span style="color: #339933;">+</span>TAMANHO_X_PATA<span style="color: #339933;">+</span>DISTANCIA_X_PATA<span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">QuadCurve2D</span>.<span style="color: #003399;">Float</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #339933;">+</span>TAMANHO_Y, x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X_PATA<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #339933;">+</span>TAMANHO_Y_PATA, x<span style="color: #339933;">+</span>TAMANHO_X_PATA, y<span style="color: #339933;">+</span>TAMANHO_Y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		x <span style="color: #339933;">=</span> xBkp<span style="color: #339933;">;</span>
&nbsp;
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Ellipse2D.<span style="color: #006633;">Float</span></span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X<span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO,y<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO,RAIO_OLHO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>,RAIO_OLHO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">BLUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Ellipse2D.<span style="color: #006633;">Float</span></span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X<span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO_CRISTALINO,y<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO_CRISTALINO,RAIO_OLHO_CRISTALINO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>,RAIO_OLHO_CRISTALINO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Ellipse2D.<span style="color: #006633;">Float</span></span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X<span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO <span style="color: #339933;">+</span> DISTANCIA_X_OLHOS,y<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO,RAIO_OLHO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>,RAIO_OLHO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">setPaint</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">BLUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g2d.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Ellipse2D.<span style="color: #006633;">Float</span></span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_X<span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO_CRISTALINO <span style="color: #339933;">+</span> DISTANCIA_X_OLHOS,y<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>TAMANHO_Y<span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>RAIO_OLHO_CRISTALINO,RAIO_OLHO_CRISTALINO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span>,RAIO_OLHO_CRISTALINO<span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ao executar a classe temos: </p>
<p><a href="http://www.vaniomeurer.com.br/wp-content/uploads/2009/11/fantasminhas-pacman.JPG"><img src="http://www.vaniomeurer.com.br/wp-content/uploads/2009/11/fantasminhas-pacman.JPG" alt="Fantasma Pac Man - Java2D" title="Fantasma Pac Man - Java2D" width="300" height="300" class="aligncenter size-full wp-image-233" /></a></p>
<p>Visite o site deles e tente resolver você também.</p>
<p>Até, Vânio Meurer (vaninhO)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2009/11/10/desenhando-o-fantasminha-do-pacman-com-java-2d/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>RandomAccessFile, escrevendo sem sustituir texto</title>
		<link>http://www.vaniomeurer.com.br/2009/11/09/randomaccessfile-escrevendo-sem-sustituir-texto/</link>
		<comments>http://www.vaniomeurer.com.br/2009/11/09/randomaccessfile-escrevendo-sem-sustituir-texto/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 19:11:50 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[escrever em arquivo]]></category>
		<category><![CDATA[randomaccessfile]]></category>
		<category><![CDATA[randomaccessfileplus]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=220</guid>
		<description><![CDATA[Post onde mostro como escrever utilizando a RandomAccessFile sem sobrescrever o texto posterior (efeito insert). Disponibilizo uma classe utilitaria (RandomAccessFilePlus) que abstrai toda a complexidade de escrever sem o efeito insert.]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<p>Buenas caros leitores, como estão? Espero que bem.</p>
<p>Hoje vim postar uma classe que fiz e ficou maneira, pelo menos eu achei.</p>
<p>
Estava estudando a classe java.io.RandomAccessFile, onde nela é possível ler e escrever em arquivos sem ter de utilizar um BufferedReader e um BufferedWriter (ou quaisquer outras duas classes para leitura e escrita), e me deparei com um &#8220;problema&#8221;, na verdade não é um problema, mas não gostei do que acontecia.</p>
<p>Quando eu estava lendo o arquivo, no meio dele eu queria escrever algum texto, usei todos os métodos e todos sobrescreviam o texto seguinte (o mesmo efeito do botão insert).<br />
Exemplo do que acontecia:</p>
<p><span style="color: #0000ff;">&#8220;Esse é um texto exemplo que estou utilizando,<br />
maneiro&#8221;</span></p>
<p>Tentei escrever &#8220;não é&#8221; antes da palavra &#8220;Maneiro&#8221; e o que aconteceu?<br />
O texto ficou assim:</p>
<p><span style="color: #0000ff;">&#8220;Esse é um texto exemplo que estou utilizando,<br />
não éro&#8221;</span></p>
<p>Só que eu queria que ficasse assim:</p>
<p><span style="color: #0000ff;">&#8220;Esse é um texto exemplo que estou utilizando,<br />
não é maneiro&#8221;</span></p>
<p>Então fui pesquisar como fazer e para minha surpresa a classe RandomAccessFile não &#8220;estica&#8221; o arquivo para inserir algo, você precisa fazer isso manualmente.</p>
<p><strong>Como fazer?</strong></p>
<p>Precisamos aumentar o tamanho do arquivo, mover o texto a partir de onde queremos escrever até o fim do arquivo e escrever o que desejamos no ponto onde movemos.</p>
<p>Fácil não? Até é, mas é meio chato.</p>
<p>E é por isso que estou aqui distribuindo a classe utilitária que criei para essa função, prazer RandomAccessFilePlus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.vaniomeurer.io</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.DataInput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.DataOutput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.RandomAccessFile</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Classe que lê e escreve em um arquivo. Utiliza a java.io.RandomAccessFile
 * porem com essa classe os caracteres escritos não sobrescrevem os caracteres
 * posteriores (efeito insert).
 * 
 * 
 * @author Vânio Meurer
 * @since 09/11/2009 16:01:13
 * @version 1.0.0
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RandomAccessFilePlus <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">DataOutput</span>, <span style="color: #003399;">DataInput</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">RandomAccessFile</span> raf<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lineSeparator<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Construtor padrão.
	 * 
	 * @param raf
	 *            Utilize uma RandomAccessFile com acesso a escrita (&quot;rw&quot;) caso
	 *            desejar escrever.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> RandomAccessFilePlus<span style="color: #009900;">&#40;</span><span style="color: #003399;">RandomAccessFile</span> raf<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">raf</span> <span style="color: #339933;">=</span> raf<span style="color: #339933;">;</span>
		lineSeparator <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> java.<span style="color: #006633;">security</span>.<span style="color: #003399;">AccessController</span>
				.<span style="color: #006633;">doPrivileged</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sun.<span style="color: #006633;">security</span>.<span style="color: #006633;">action</span>.<span style="color: #006633;">GetPropertyAction</span><span style="color: #009900;">&#40;</span>
						<span style="color: #0000ff;">&quot;line.separator&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Quebra de linha no arquivo.
	 * 
	 * @throws IOException
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> newLine<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		writeBytes<span style="color: #009900;">&#40;</span>lineSeparator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> write<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> length, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> write<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> arg0.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> length, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> write<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arg0, <span style="color: #000066; font-weight: bold;">int</span> arg1, <span style="color: #000066; font-weight: bold;">int</span> arg2<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>arg2, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>arg0, arg1, arg2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> arg2, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeBoolean<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">boolean</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeBoolean</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeByte<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeByte</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> length, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeBytes<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> arg0.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeBytes</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> length, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeChar<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeChar</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeChars<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> arg0.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeChars</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> length, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeDouble<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeDouble</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">8</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeFloat<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeFloat</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeInt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeInt</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeLong<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeLong</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">8</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeShort<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeShort</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		backToPosition<span style="color: #009900;">&#40;</span>filePointer <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span>, b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeUTF<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> length <span style="color: #339933;">=</span> arg0.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> filePointer <span style="color: #339933;">=</span> raf.<span style="color: #006633;">getFilePointer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> increaseFile<span style="color: #009900;">&#40;</span>length, filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">writeUTF</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> increaseFile<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> length, <span style="color: #000066; font-weight: bold;">long</span> filePointer<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>raf.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> filePointer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">readFully</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span>raf.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">seek</span><span style="color: #009900;">&#40;</span>filePointer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> b<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> backToPosition<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> position, <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> b<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		raf.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		raf.<span style="color: #006633;">seek</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> readBoolean<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readBoolean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">byte</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">char</span> readChar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readChar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">double</span> readDouble<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readDouble</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">float</span> readFloat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readFloat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> readFully<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		raf.<span style="color: #006633;">readFully</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> readFully<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arg0, <span style="color: #000066; font-weight: bold;">int</span> arg1, <span style="color: #000066; font-weight: bold;">int</span> arg2<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		raf.<span style="color: #006633;">readFully</span><span style="color: #009900;">&#40;</span>arg0, arg1, arg2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> readInt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> readLine<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> readLong<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">short</span> readShort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readShort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> readUTF<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readUTF</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> readUnsignedByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readUnsignedByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> readUnsignedShort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">readUnsignedShort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> skipBytes<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf.<span style="color: #006633;">skipBytes</span><span style="color: #009900;">&#40;</span>arg0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		raf.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> seek<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> pos<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		raf.<span style="color: #006633;">seek</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Getter RandomAccessFile
	 * 
	 * @return
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">RandomAccessFile</span> getRAF<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> raf<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Setter RandomAccessFile
	 * 
	 * @param raf
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setRAF<span style="color: #009900;">&#40;</span><span style="color: #003399;">RandomAccessFile</span> raf<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">raf</span> <span style="color: #339933;">=</span> raf<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><br class="spacer_" /></p>
<p>Aqui uma classe que faz o teste que comentei acima:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">br.com.vaniomeurer.io</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.RandomAccessFile</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Classe que faz um teste simples na classe RandomAccessFilePlus.
 * 
 * @author Vânio Meurer
 * @since 09/11/2009 16:49:08
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RandomAccessFilePlusTest <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D:/texto.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		RandomAccessFilePlus rafp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RandomAccessFilePlus<span style="color: #009900;">&#40;</span>
				<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RandomAccessFile</span><span style="color: #009900;">&#40;</span>file, <span style="color: #0000ff;">&quot;rw&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Leu a primeira linha</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>rafp.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Escreveu 'não é'</span>
		rafp.<span style="color: #006633;">writeBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;não é &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Movendo o ponteiro ao inicio</span>
		rafp.<span style="color: #006633;">seek</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Lendo o arquivo completo</span>
		<span style="color: #003399;">String</span> linha <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>linha <span style="color: #339933;">=</span> rafp.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>linha<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Fechando arquivo</span>
		rafp.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> O arquivo texto.txt originalmente continha o texto: </p>
<p><span style="color: #0000ff;">&#8220;Esse é um texto exemplo que estou utilizando,<br />
maneiro&#8221;</span></p>
<p>Depois de executado a classe de teste ficou assim:</p>
<p><span style="color: #0000ff;">&#8220;Esse é um texto exemplo que estou utilizando,<br />
não é maneiro&#8221;</span></p>
<p>Porque eu não herdei a classe RandomAccessFile? Porque a classe RandomAccessFile possui métodos finais e eu não poderia sobrescreve-los.</p>
<p>Por hoje seria isso mesmo, no futuro pretendo lançar algum jarzinho com algumas classes utilitarias que crio de vez em quando, porem acabo excluindo-as.</p>
<p>Até, Vânio Meurer (vaninhO)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2009/11/09/randomaccessfile-escrevendo-sem-sustituir-texto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easter Egg em sites</title>
		<link>http://www.vaniomeurer.com.br/2009/10/17/easter-egg-em-sites/</link>
		<comments>http://www.vaniomeurer.com.br/2009/10/17/easter-egg-em-sites/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 15:52:12 +0000</pubDate>
		<dc:creator>Vanio Meurer</dc:creator>
				<category><![CDATA[Diversos]]></category>
		<category><![CDATA[easter eggs]]></category>
		<category><![CDATA[easter eggs sites]]></category>
		<category><![CDATA[ovos de pascoa]]></category>

		<guid isPermaLink="false">http://www.vaniomeurer.com.br/?p=214</guid>
		<description><![CDATA[Post falando sobre os easter eggs (ovos de páscoa) em sites da web. São mostrados alguns exemplos e como visualizar os easter eggs nos mesmos.]]></description>
			<content:encoded><![CDATA[<p>Buenas pessoas,</p>
<p>Vocês já ouviram falar de &#8220;Easter Egg&#8217;s&#8221; (Ovos de Páscoa)? (<a title="Easter Egg Wiki" href="http://pt.wikipedia.org/wiki/Ovo_de_p%C3%A1scoa_%28virtual%29" target="_blank">wiki</a>)</p>
<p>Eles são bem comuns em jogos, porem agora começaram a surgir em páginas da web.<br />
 Como assim? Easter Eggs em páginas? Exatamente.<br />
 Segue abaixo alguns exemplos e como visualizar os easter eggs:</p>
<p>A &#8220;senha&#8221; padrão para todos os sites é pressionar as teclas direcionais na seguinte seqüência:<br />
 cima, cima, baixo, baixo, esquerda, direita, esquerda, direita<br />
 e em seguida pressionar as teclas:<br />
 b, a</p>
<p>Alguns sites que você pode fazer:</p>
<p><a title="JQuery" href="http://www.jquery.com" target="_blank">http://www.jquery.com</a><br />
 <a title="Google Reader" href="http://www.google.com.br/reader/" target="_blank">http://www.google.com.br/reader/</a><br />
 <a title="Vânio Meurer - Java Programmer" href="http://www.vaniomeurer.com.br" target="_blank">http://www.vaniomeurer.com.br</a> (sim, também coloquei um easter egg aqui!)<br />
 <a title="The Globe And Mail" href="http://www.theglobeandmail.com" target="_blank">http://www.theglobeandmail.com</a></p>
<p>Nesse último você precisa fazer algumas coisinhas a mais, são elas:<br />
 Assim que completar a “senha”, vai abrir um alert de javascript, você pressiona o botão OK e em seguida pressiona as teclas SHIFT + SPACE simultaneamente, vai surgir uma espécie de console, digite “contra” (sem aspas) e veja o resultado.</p>
<p>Caso você digite a &#8220;senha&#8221; e nada acontecer, tente dar reload na página e antes de fazer qualquer coisa, digite a &#8220;senha&#8221;.</p>
<p>Aqui nessa página certifique-se que o foco não está no applet do post <a title="Projeto Inicial de Jogo em Java" href="http://www.vaniomeurer.com.br/2009/10/08/projeto-inicial-de-jogo-em-java/" target="_blank">Projeto Inicial de Jogo em Java</a>, caso estiver, clique na página (fora do applet) para que você possa digitar a &#8220;senha&#8221;.</p>
<p>OBS: aparentemente os easter eggs não estão funcionando no Internet Explorer versão 6.</p>
<p>Hoje o post foi bem incomum, mas é divertidinho <img src='http://www.vaniomeurer.com.br/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <br />
 Vânio Meurer (vaninh0)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vaniomeurer.com.br/2009/10/17/easter-egg-em-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

